fastjson和Jackson中关于空值的处理
fastjson
fastjson默认转换中回把null值的参数去除,如果需要空值显示,如下操作:
JSONObject.toJSONString(resultJson, SerializerFeature.WriteMapNullValue);
Jackson
Jackson中默认保留空值,如果想去除空值,可通过一下操作。
1.注解方式
@JsonInclude(Include.NON_EMPTY)
2.objectMapper
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);