JSON忽略指定属性

  • https://blog.csdn.net/insis_mo/article/details/92760527
  • FastJson的使用方法:
  1. 在bean中的定义属性上面使用注解@JSONField ,然后JSON.toJSONString()返回即可
  2. 使用SimplePropertyPreFilter指定序列化字段:SimplePropertyPreFilter filter = new SimplePropertyPreFilter(Bean.class, "FieldName"); 然后JSON.toJSONString()返回即可
  • JackSon的使用方法:
  1. 在Bean类名上使用@JsonIgnoreProperties({"fieldname1", "fieldName2"}), 然后(new ObjectMapper()).writeValueAsString(beanName);即可

  2. 在字段上使用@JsonIgnore,然后(new ObjectMapper()).writeValueAsString(beanName);即可

posted @ 2020-10-14 11:29  路要一步一步走  阅读(1185)  评论(0编辑  收藏  举报