<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency>
name : 给字段起别名
ordinal :用来排序 输出json字符串中key属性的先后顺序 可以用 @JSONType (orders={})来代替
format : 用来日期格式化
serialize :指定字段不序列化
deserialize :指定字段不序列化
执行
public static void main(String[] args) { WqTestEntity wqEntity = new WqTestEntity(); wqEntity.setTestInt(1); wqEntity.setTestString("aaa"); wqEntity.setTestDouble(1.01); wqEntity.setTestDate(new Date()); wqEntity.setTestSerializable("111"); System.out.println(JSON.toJSONString(wqEntity)); }结果
{"test_date":"20200701","test_double":1.01,"test_int":1,"test_string":"aaa"}