Thomas Stubbe
Thomas Stubbe

Reputation: 1985

How to ignore certain fields with Jackson's ObjectMapper.readerForUpdating

I'm using Jackson 2.7.0

I'm trying to ignore encodingType when updating an existing object with some new values:

ObjectMapper om = new ObjectMapper();
om.readerForUpdating(message).readValue(messageSubset);

message contains a value for encodingType.
messageSubset (JSON-string) does not contain an entry (no key-value) for encodingType.

What I've tried:

Non of the above work! Any help?
I suppose this has something to do with readerForUpdating and/or the fact that one of them is being updated.

Upvotes: 5

Views: 6478

Answers (1)

Thomas Stubbe
Thomas Stubbe

Reputation: 1985

I fixed the problem by configuring the ObjectMapper like this (not sure if these are all needed though):

om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);

And on the Message class for the properties needed:

@JsonIgnore on the setter (excludes it when parsing to the Java object)
@JsonProperty on the getter (includes it when parsing to the JSON object)

Upvotes: 3

Related Questions