欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

相关标签: 个人学习笔记