SpringMVC的JSON处理(FastJson)

671 阅读1分钟

如果不想使用Jackson,则也可以使用其他的Json处理方案:FastJson

(1)安装FastJson

image.png

(2)使用@ResponseBody @ResquestBody @RestController 使用的方法不变

(3)常用注解

日期格式化:@JSONField(fromat="yyyy/MM/dd")

属性名修改:@JSONFiled(name="birth")

忽略属性:@JSONFiled(serialize=false)

默认会忽略所有的null值,有此注解会输出null
包含null值:@JSONField(serializeFeatures = SerializerFeature.WriteMapNullValue)

null的String输出会为""
@JSONField(serialFeatures = SerialFeatures = SerialFeature.WriteNullStringAsEmpty)

image.png


自定义序列化:@JSONField(serializeUsing = MySerialier2.class)
image.png