Jackson returns the result of the processing of four kinds of notes

Jackson returns the result of the processing of four kinds of notes

Required jar package

 <dependency>
     <groupId>com.fasterxml.jackson.core</groupId>
     <artifactId>jackson-core</artifactId>
     <version>2.9.9</version>
   </dependency>
  <dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
     <version>2.9.9</version>
  </dependency>
  <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
     <version>2.9.9</version>
  </dependency>

If the project is based on springboot created, only need to introduce

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

Specific effects: effective pro-test

 	@JsonIgnore //忽略id不显示
    private Integer id;
    @JsonInclude(JsonInclude.Include.NON_NULL) //如果当前值为空不显示
    private String name;
    @JsonProperty("abc") // 相当于给phone 字段起别名
    private String phone;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",locale = "zh",timezone = "GMT+8")//格式化日期
    private Date createTime;
Published 68 original articles · won praise 7 · views 2512

Guess you like

Origin blog.csdn.net/Cui6023056/article/details/104962067