Skip to content

Instantly share code, notes, and snippets.

@patelm5
Created February 28, 2014 10:38
Show Gist options
  • Save patelm5/9268866 to your computer and use it in GitHub Desktop.
Save patelm5/9268866 to your computer and use it in GitHub Desktop.
Enum deserialization override with some class information stored.
DeserializerFactory withAdditionalDeserializers = BeanDeserializerFactory.instance.withAdditionalDeserializers(setupEnumDeserializer());
DefaultDeserializationContext.Impl dc = new DefaultDeserializationContext.Impl(withAdditionalDeserializers);
ObjectMapper defaultMapper = new ObjectMapper(null, null, dc);
private Deserializers setupEnumDeserializer() {
Deserializers d = new Deserializers.Base() {
@Override
public JsonDeserializer<?> findEnumDeserializer(Class<?> type,
DeserializationConfig config, BeanDescription beanDesc)
throws JsonMappingException
{
if (beanDesc.getType().getContentType() != null){
return new JaxbEnumDeserializer( beanDesc.getType().getContentType().getRawClass());
}else{
return new JaxbEnumDeserializer(beanDesc.getType().getRawClass());
}
}
};
return d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment