jackson notes detail

jackson's dependence maven

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

In this alone sum up, recently used to comment.

1. @ JsonProperty: This annotation for the attribute, the name of the action attribute is serialized as another name, such as the sequence into trueName attribute name, @ JsonProperty ( "name").

Rename the attribute name, such as Java object's properties are in accordance with the hump writing specifications, but when used in database design scene is underlined in many connections, making maps of time here

@JsonProperty(value = "SORT_NUM")
@Column(name = "sort_num")
private String sortNum;

2. @ JsonIgnore this annotation for the property or method (preferably the attributes) for the annotated completely ignored and corresponding method attribute field

@JsonIgnore
@ApiModelProperty("密码")
private String password;

3. @ JsonIgnoreProperties This annotation is annotation class, the role is json serialization java bean in some of the properties ignored, serialization and de-serialization are affected.
For example: User entity fields have the password field, when the user returns to the reception time information, of course, undesirable to password values are returned together,
it is possible to add comments on the password attribute JsonIgnore
Alternatively, the User class add comments

@JsonIgnoreProperties(value = "{password}")

4. @ JsonFormat this annotation for the property or method (preferably on the property), the Date type can easily be converted directly to our desired mode.

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;

5. @ JsonSerialize this annotation for the attributes or getter methods for embedding the code in our custom serialization, such as restrictions on its rear two decimal places when serializing a double.

6. @ JsonDeserialize this annotation is used on the fields or setter methods for deserialization code that may be embedded in our custom, similar to the above @JsonSerialize.

7. @ JsonInclude null attribute value does not participate in serialization.

@JsonInclude(Include.NON_NULL)
Published 80 original articles · won praise 140 · views 640 000 +

Guess you like

Origin blog.csdn.net/linjpg/article/details/99874762