Is there any jackson json strategy (using annotations or another way), that will execute some logic prior and post deserialization of field?
There isn't any specific feature to do post- or pre-processing at this point; and this sort of gets close to boundaries of what data binding should do. If I had to do this for specific fields, I would probably just add it in setter, since that is simple thing to do and works; but requires same logic in all relevant setters.
@JsonDeserialize can also be used for individual properties (field, setter), so you could create a custom deserializer: and since you want post-processing, you could just locate "real" deserializer (ideally by making JsonDeserializer
implement either ContextualDeserializer
or ResolvableDeserializer
-- this may not matter here, but for general case it's done here to avoid problems with cyclic dependencies), delegate to it, and modify value. This assumes it is value you care about more than field.
Finally, there are also ways to modify BeanDeserializer
instances (by registering BeanDeserializerModifier
) -- you could sub-class relevant components (SettableBeanProperty I think...) to hook in additional handling, or even replace deserializer to use, keeping a reference to the original "default" deserializer.
But in the end, your case sounds like something that may be best handled by something else: for example Bean Validation API (jsr-303) seems like a potentially good match for post-processing logic. Since it is somewhat orthogonal to data binding, it could be a superior alternative since it would be independent of data binding (jackson), reusable, all the good stuff.