赞
踩
webClient中
.accept(MediaType.APPLICATION_JSON)
决定返回值是什么格式一般情况可以不写,但这里要获取JSON格式的
.bodyToMono(String.class)
指定返回类型
fastJSON2中
Student student = JSON.parseObject(result, Student.class, JSONReader.Feature.SupportSmartMatch);
可以将JSON和java的class属性自动进行匹配
全代码如下:
- WebClient webClient = WebClient.create(yourAPI);
- public void tokenToApi(String token) {
- String result = webClient
- .get()
- .uri(uriBuilder -> uriBuilder
- .path("/your/path/")
- .queryParam("access_token", token)
- .build())
- .accept(MediaType.APPLICATION_JSON)
- .retrieve()
- .bodyToMono(String.class)
- .block();
- log.info("学生:{}",result);
-
- // fastJSON JSON 反序列化 + 转驼峰命名
- Student student = JSON.parseObject(result, Student.class, JSONReader.Feature.SupportSmartMatch);
- log.info("反序列化:{}", student);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。