gigi2
gigi2

Reputation: 2194

ignore a property at object mapper level?

I have a domain object that gets deserialized either thru Spring MVC or an internal object mapper in my service layer. I need to ignore the input of 1 field when it is being deserialized thru Spring MVC, but not with the internal object mapper in service layer. Is it doable?

Any hints/clues are deeply appreciated.

Upvotes: 1

Views: 1842

Answers (1)

Darshan Mehta
Darshan Mehta

Reputation: 30809

You can do it using Mixin annotations, (documentation here). You can create another class with @JsonIgnore field and configure in your internal objectMapper, e.g.:

abstract class MixIn {
   @JsonIgnore int getXXX(); 
}

objectMapper.getSerializationConfig().addMixInAnnotations(Model.class, MixIn.class);

You can configure this in service layer objectMapper which would mean your external objectMapper would still be able to serialize/deserialize that field.

Upvotes: 2

Related Questions