On Fri, Aug 18, 2017 at 1:32 PM, Vladimir <[email protected]> wrote:
>
> I implement the ResolvableDeserializer within my custom deserializer, which
> gives me the reference to the default JsonDeserializer<?>.
> Id like to invoke the default deserializer on the "Jail" JsonNode to return
> to me a Jail object
>
> public class BadStudentDeserializer extends StdDeserializer<BadStudent>
>     implements ResolvableDeserializer{
>   private static final long serialVersionUID = 1L;
>   private JsonDeserializer<?> defaultDeserializer;
>
>
>   public BadStudentDeserializer(JsonDeserializer<?> defaultDeserializer) {
>     super(BadStudent.class);
>     this.defaultDeserializer = defaultDeserializer;
>   }
>
>   @Override
>   public BadStudent deserialize(JsonParser p, DeserializationContext ctxt)
>       throws IOException, JsonProcessingException {
>     JsonNode jsonTree = p.getCodec().readTree(p);
>
>     String id = jsonTree.get("id").asText();
>     String weapon = jsonTree.get("weapon").asText();
>     JsonNode jailNode = jsonTree.get("jail");
>     JsonParser jailNodeParser = jailNode.traverse();
>     //advance it as per documentation
>     jailNodeParser.nextToken();
>     //this doesnt work
>     Jail jail = (Jail)defaultDeserializer.
>         deserialize(jailNodeParser, ctxt);
>     return new BadStudent(id, weapon, jail);
>   }
>
>
>   @Override
>   public void resolve(DeserializationContext ctxt) throws
> JsonMappingException {
>     ((ResolvableDeserializer) defaultDeserializer).resolve(ctxt);
>
>   }
>
>
>
>
> How do I provide the defaultDeserializer a clue as to what class TYPE a tree
> node is, so that it can pick up the right deserializer or that treeNode?
>
> Hope I am able to explain myself clearly.

`JsonNode` has methods (`isObject()`, `isArray()`), if you are
interested in type of json node read.
But just looking at naming, it seems odd that you would delegate
contents of `jail` to default POJO
deserializer that would be used for `BadStdudent`?

-+ 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 [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to