Jackson ignores some properties

  1. @JsonIgnoreProperties

    This annotation is a class annotation, and its function is to ignore some properties in the java bean during json serialization, and both serialization and deserialization are affected.

  2. @JsonIgnore

      This annotation is used on properties or methods (preferably on properties), and has the same effect as @JsonIgnoreProperties above.

     age attribute is not generated when generating json 

    public class user { 

    private String name; 

    @JsonIgnore 

       private int age; 

     } 

@JsonIgnore doesn't work

  • It will lose its effect if the naming is not standardized. (eg Ename, Eage for non-canonical names. "nameE", "ageE" for canonical names

  • jar related may not match the framework import org.codehaus.jackson.annotate.JsonProperty or import com.fasterxml.jackson.annotation.JsonIgnore 

3. @JsonFormat

This annotation is used on properties or methods (preferably on properties), which can easily convert the Date type directly into the pattern we want, such as @JsonFormat(pattern = “yyyy-MM-dd HH-mm-ss”)

4. @JsonSerialize

This annotation is used on properties or getter methods to embed our custom code during serialization, such as limiting two decimal points after serializing a double.

5. @JsonDeserialize

This annotation is used on properties or setter methods to embed our custom code during deserialization, similar to @JsonSerialize above

@Transient

@Transient indicates that the attribute is not a mapping to a field of a database table, and the ORM framework will ignore this attribute;
if an attribute is not a field mapping of a database table, it must be marked as @Transient, otherwise the ORM framework defaults to its annotation @Basic ;

//Indicates that the field does not exist in the database table

@Transient
public int getAge() {
 return 1+1;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324397885&siteId=291194637