fastjson基本使用
依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.39</version> </dependency>
简单测试
为null的属性不会被打印。
package com.ytkj.mozq_excel_server.pojo.car; import java.math.BigDecimal; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** * <p> * * </p> * * @author mozq * @since 2019-10-30 */ @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) public class Car implements Serializable { private static final long serialVersionUID = 1L; public static void main(String[] args) { Car car = new Car(); car.setCreateTime(LocalDateTime.now()); car.setBrand("宝马"); System.out.println(JSONObject.toJSONString(car)); //{"brand":"宝马","createTime":"2019-10-30"} } /** * 车辆主键 */ @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 砂厂id */ private Integer companyId; /** * 车牌号 */ private String carLicense; /** * 车辆载重 */ private BigDecimal carCapacity; /** * 车主姓名 */ private String masterName; /** * 车主电话 */ private String masterPhone; /** * 车辆类型 */ private String type; /** * 车辆品牌 */ private String brand; /** * 车辆状态 1-正常 2-禁用 */ private Integer status; @JSONField(format="yyyy-MM-dd") private LocalDateTime createTime; private LocalDateTime updateTime; private Integer updateUid; }