Changing a custom deserializer at runtime?

214 views
Skip to first unread message

Thierry-Dimitri Roy

unread,
Mar 24, 2014, 12:58:53 PM3/24/14
to jackso...@googlegroups.com
I have set on a field a custom deserializer that I need 99% of the time:

@JsonDeserialize(using = EditionFilesDeserializer.class)
public EditionFiles files = null;

But 1% of the time, I want to use the default Jackson deserializer. So basically I want Jackson to ignore the @JsonDeserialize annotation.

I tried changing the deserializer at runtime, but couldn't find a way to do it. Does anyone has any suggestion?
Thanks,
tdr :) 

Tatu Saloranta

unread,
Mar 24, 2014, 1:51:21 PM3/24/14
to jackso...@googlegroups.com
This is where BeanDeserializerModifier interface (instance of which can be registered via module) comes in handy, since it can take the default (de)serializer, construct custom deserializer, and decide which one to call dynamically.

But you could also make your custom deserializer implement `ContextualDeserializer`, and when getting a call to `createContextual()`, fetch the default deserializer used for `EditionFiles` (from DeserializationContext), and hold a reference to it, so that you can dynamically choose which one to use.

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages