简体   繁体   中英

Jackson mapper: ignore certain properties when writing?

I use JSON mapper to read an object from a string and then write the string from the object. I would like to be able to ignore some properties only when writing. What is the easiest way to accomplish this?

On the interface you can use the @JsonIgnoreProperties(ignoreUnknown=true) annotation to ignore any fields that have not been specified.

For example:

@JsonIgnoreProperties(ignoreUnknown=true)
public static interface Point {
    double getLatitude();

    double getLongitude();
}

This will ignore any other fields that are serialized using the Point interface.

You can use @JsonProperty(access = Access.WRITE_ONLY) to ignore a property for serialization.

You can fine more information about this property at the below link.

https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonProperty.Access.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM