当前位置:   article > 正文

webClient + fastJSON2 获取json格式的数据,同时解析至java class 并 下划线转驼峰_faster json转驼峰

faster json转驼峰

webClient中

.accept(MediaType.APPLICATION_JSON)

决定返回值是什么格式一般情况可以不写,但这里要获取JSON格式的

                .bodyToMono(String.class)

 指定返回类型

fastJSON2中

        Student student = JSON.parseObject(result, Student.class, JSONReader.Feature.SupportSmartMatch);

可以将JSON和java的class属性自动进行匹配

全代码如下:

  1. WebClient webClient = WebClient.create(yourAPI);
  2. public void tokenToApi(String token) {
  3. String result = webClient
  4. .get()
  5. .uri(uriBuilder -> uriBuilder
  6. .path("/your/path/")
  7. .queryParam("access_token", token)
  8. .build())
  9. .accept(MediaType.APPLICATION_JSON)
  10. .retrieve()
  11. .bodyToMono(String.class)
  12. .block();
  13. log.info("学生:{}",result);
  14. // fastJSON JSON 反序列化 + 转驼峰命名
  15. Student student = JSON.parseObject(result, Student.class, JSONReader.Feature.SupportSmartMatch);
  16. log.info("反序列化:{}", student);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/758577
推荐阅读
相关标签
  

闽ICP备14008679号