@JsonIgnore 注解
2016-12-19 13:26
190 查看
jackson包实现json、对象、Map之间的转换。
User user=new User();
user.setId("01");
user.setName("张三疯");
user.setAge(200);
user.setPay(6666.88);
user.setValid(true);
user.setOne('E');
user.setBirthday(new Date(20l*366*24*3600*1000)); //1990年
Link link = new Link();
link.setAddress("河南省济源市");
link.setPhone("13899995555");
link.setQq("123456");
user.setLink(link);
Map map=new HashMap();
map.put("aa", "this is aa");
map.put("bb", "this is bb");
map.put("cc", "this is cc");
user.setMap(map);
List list=new ArrayList(){};
list.add("普洱");
list.add("大红袍");
user.setList(list);
Set set=new HashSet();
set.add("篮球");
set.add("足球");
set.add("乒乓球");
user.setSet(set);
ObjectMapper mapper = new ObjectMapper(); //转换器
//测试01:对象--json
String json=mapper.writeValueAsString(user); //将对象转换成json
System.out.println(json);
/* 结果如下:
{"id":"01","name":"张三","age":33,"pay":6666.88,"valid":true,"one":"E","birthday":1465185448998,
"link":{"phone":"13899995555","address":"河南省济源市","qq":"123456"},
"map":{"aa":"this is aa","bb":"this is bb","cc":"this is cc"},
"list":["普洱","大红袍"],
"set":["乒乓球","足球","篮球"]}
Map m = mapper.readValue(json, Map.class); //json转换成map
User user=new User();
user.setId("01");
user.setName("张三疯");
user.setAge(200);
user.setPay(6666.88);
user.setValid(true);
user.setOne('E');
user.setBirthday(new Date(20l*366*24*3600*1000)); //1990年
Link link = new Link();
link.setAddress("河南省济源市");
link.setPhone("13899995555");
link.setQq("123456");
user.setLink(link);
Map map=new HashMap();
map.put("aa", "this is aa");
map.put("bb", "this is bb");
map.put("cc", "this is cc");
user.setMap(map);
List list=new ArrayList(){};
list.add("普洱");
list.add("大红袍");
user.setList(list);
Set set=new HashSet();
set.add("篮球");
set.add("足球");
set.add("乒乓球");
user.setSet(set);
ObjectMapper mapper = new ObjectMapper(); //转换器
//测试01:对象--json
String json=mapper.writeValueAsString(user); //将对象转换成json
System.out.println(json);
/* 结果如下:
{"id":"01","name":"张三","age":33,"pay":6666.88,"valid":true,"one":"E","birthday":1465185448998,
"link":{"phone":"13899995555","address":"河南省济源市","qq":"123456"},
"map":{"aa":"this is aa","bb":"this is bb","cc":"this is cc"},
"list":["普洱","大红袍"],
"set":["乒乓球","足球","篮球"]}
Map m = mapper.readValue(json, Map.class); //json转换成map
相关文章推荐
- @JsonIgnore注解
- jackson中@JsonProperty、@JsonIgnore等常用注解总结
- Jackson 解析j@JsonIgnorePropertiesson数据之忽略解析字段注解
- Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
- @JsonIgnoreProperties注解不起作用的问题解决
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- 问题:在程序中保存数据到索引库,发生异常jackson数据转换异常,造成死循环栈溢出 解决@JsonIgnore注解
- [转]Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
- Java+Hibernation+MySQL的@JsonIgnore注解
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Json注解属性JsonIgnoreProperties,JsonInclude,JsonProperty总结小记
- Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
- Hibernate JPA中@Transient、@JsonIgnoreProperties、@JsonIgnore、@JsonFormat、@JsonSerialize等注解解释
- Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
- 关于双向多对一的@JsonIgnore注解使用方法
- Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties