I have a pojo that populates a hidden variable when its setter methods are invoked.
My pojo is almost identical to: Gson POJO mapping loses custom field value
I am using jackson 1.9.6 in my JAX-RS project. When a REST call is made, it consumes JSON and automagically converts it to an instance of the pojo. I believe jackson is using reflection to do this. The reason this is bad for me is because reflection bypasses the setter methods and my hidden variable is never populated.
How do I tell jackson to avoid reflection and to specifically call the getter/setter methods? Do I have to tag each pojo with @JsonDeserialize? If so, how would I write a generic Deserializer (aka MyDeserializer extends JsonDeserializer<T>
) to handle different pojos? Is there a better way that I'm not thinking of?
Note: In test cases (outside of REST) I have had success using ObjectMapper.readValue(json,class)
, but I'm not sure how to migrate that code into a JsonDeserializer.