Created
February 28, 2014 10:38
-
-
Save patelm5/9268866 to your computer and use it in GitHub Desktop.
Enum deserialization override with some class information stored.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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