3

I am using Jackson 2 and struggled with dynamic filtering of properties during deserialization.

My idea is to load an entity and just read the changes:

objectMapper.readerForUpdating(entity).readValue(json)

I was trying to use @JsonView, which works for the simple cases.

I get an update of EntityA and the reader should only accept the id of EntityB, which is used to look up the foreign entity via EntityManager.

Using @JsonView allows me to handle it, but I need to have different view classes for all my use cases, f.e. updating EntityB only.

class Views {
    public static class Update {
    }
    public static class Display extends Update {
    }
}

class EntityA {
    @JsonView(Views.Update)
    EntityB b;

    ...
}

class EntityB {
    @JsonView(Views.Update)
    Integer id;
    @JsonView(Views.???)
    String value;
    ...
}

Is there any way to filter the properties dynamically during deserialization like the @JsonFilter?
I found an old answer to do it with BeanDeserializerModifier, but I hoped there is a better way.

Community
  • 1
  • 1
CSchulz
  • 10,882
  • 11
  • 60
  • 114

0 Answers0