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?
Asked
Active
Viewed 6,737 times
2
-
Are you using Spring? – anubhava Mar 20 '13 at 21:01
-
2Answer here http://stackoverflow.com/questions/12505141/only-using-jsonignore-during-serialization-but-not-deserialization – eugen Mar 20 '13 at 22:07
-
Thanks eugen! Putting the JsonIgnore property ONLY on the getter is exactly what I needed! – Trant Mar 21 '13 at 16:10
2 Answers
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.

Srikar
- 119
- 1
- 5