2

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?

Trant
  • 3,461
  • 6
  • 35
  • 57

2 Answers2

2

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.

tdedecko
  • 1,442
  • 10
  • 15
  • This did not do the trick. When I read the json object and write it to string it includes "property : null" for everything not set – Trant Mar 21 '13 at 14:46
1

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

Srikar
  • 119
  • 1
  • 5