fastjson解析
程序员文章站
2022-04-08 16:07:13
...
一
maven引入包
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
二
xxxApplication加一段
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters){
super.configureMessageConverters(converters);
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat
);
fastConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastConverter);
}
三
例如
@JSONField(format = "yyyy-MM-dd HH:mm")
private Date createTime;
@JSONField(serialize = false)
private String remarks;
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@RequestMapping("/ademo")
public Demo ademo(){
Demo demo = new Demo();
demo.setCreateTime(new Date());
demo.setRemarks("备注");
return demo;
}
四
ok
上一篇: JavaScript文档对象模型-Document类型
下一篇: Java知识点汇总