<!-- 9.fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency>
jsonArray.toJsonString(object)默认首字母小写,但是有些时候,不想要这种默认机制,可以在实体类上加上@JSONField
package com.hainei.pojo.bo.toZonesData; import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; /** * Created with IntelliJ IDEA. * User:wq * Date:2020/12/19 * Time: 15:19 * Description: 10.1作业人员在岗在位数据 */ @Data public class ZonesWorkPeoleBO { @JSONField(name = "QYBM") private String QYBM; @JSONField(name = "GWID") private String GWID; @JSONField(name = "GWMC") private String GWMC; @JSONField(name = "GWDD") private String GWDD; @JSONField(name = "GWSJ") private String GWSJ; @JSONField(name = "RYBMA") private String RYBMA; @JSONField(name = "RYXM") private String RYXM; @JSONField(name = "ZGRYSL") private String ZGRYSL; @JSONField(name = "RCSJ") private String RCSJ; @JSONField(name = "LCSJ") private String LCSJ; @JSONField(name = "STATUS") private Integer STATUS; private String createDate ; private String createBy; private String updateDate ; private String updateBy; private Integer Version; private Integer isHistory; private Integer Sync; private String syncDate; }
光这样还不行,要替换springBoot的默认json转化机制,需要在启动类App中注入一个bean。这样才能生效。
@Bean public HttpMessageConverters fastJsonHttpMessageConverters() { FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }