模板网站如何建设,南通 网络 公司网站,简洁的企业网站,怎样做视频网站的外链前些天发现了一个巨牛的人工智能学习网站#xff0c;通俗易懂#xff0c;风趣幽默#xff0c;忍不住分享一下给大家。点击跳转到教程。 一、从json字符串转换出对象
Pager类#xff1a;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
JsonIgnoreProper…前些天发现了一个巨牛的人工智能学习网站通俗易懂风趣幽默忍不住分享一下给大家。点击跳转到教程。 一、从json字符串转换出对象
Pager类
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
JsonIgnoreProperties(ignoreUnknowntrue)
public class Pager {private int nowPage;private int pageSize;public int getNowPage() {return nowPage;}public void setNowPage(int nowPage) {this.nowPage nowPage;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize pageSize;}}
使用JsonIgnoreProperties(ignoreUnknowntrue) 忽略没有传入的属性否则每一个set方法都必须在字符串中找到对照找不到就会报错。
转换
ObjectMapper objectMapper new ObjectMapper();
Pager pager objectMapper.readValue(jsonString, Pager.class);
其中 jsonString 为 json 字符串转换得到一个 Pager 类对象。
转自https://blog.csdn.net/chemmuxin1993/article/details/52839463 二、String与对象互转 jackson转换工具 private static final ObjectMapper objectMapper new ObjectMapper().configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
使用 对象转 json
String str objectMapper.writeValueAsString(new MessageEntity());
json 转对象
ListString tidList objectMapper.readValue(tidListSrt,new TypeReferenceListString() {}); 转自https://blog.csdn.net/csdn2193714269/article/details/78844753