I have a problem with a custom deserializer in Jackson. I want to access the default serializer to populate the object I'm deserializing into. After filling in, I will do a few custom things, but first I want to deserialize the object with Jackson's default behavior.
This is the code that I have at the moment.
public class UserEventDeserializer extends StdDeserializer<User> { private static final long serialVersionUID = 7923585097068641765L; public UserEventDeserializer() { super(User.class); } @Override @Transactional public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); User deserializedUser = null; deserializedUser = super.deserialize(jp, ctxt, new User());
What I need is a way to initialize the default deserializer so that I can pre-populate my POJO before starting my custom logic.
When calling deserialization from a custom deserializer. It seems that the method is being called from the current context, regardless of how I create the serializer class. Due to annotation in my POJO. This throws an exception for obvious reasons.
I tried to initialize the BeanDeserializer but the process is extremely complicated and I could not find the right way to do this. I also tried overloading the AnnotationIntrospector no avail, believing that this could help me ignore the annotation in the DeserializerContext . Finally, I have JsonDeserializerBuilders with JsonDeserializerBuilders I may have had some success, although it took some magic to get this to get the application context from Spring. I would appreciate any thing that could lead me to a cleaner solution, such as how I can build a deserialization context without reading the JsonDeserializer annotation.
java spring jackson hibernate
Pablo Jomer Aug 19 '13 at 12:02 2013-08-19 12:02
source share