Tatu,
That makes sense, I did not realize the context provided methods for that.
What did you mean by:
*This can be done either from `deserialize()`, or from initial call
to `resolve()`. *
Now that I am looking at the java docs I see:
JsonNode jailNode = jsonTree.get("jail");
JsonParser jailNodeParser = jailNode.traverse();
Jail jail = ctxt.readValue(jailNodeParser, Jail.class);
Is that what you meant?
On Friday, August 18, 2017 at 6:28:40 PM UTC-4, Tatu Saloranta wrote:
>
> On Fri, Aug 18, 2017 at 2:58 PM, Vladimir <[email protected]
> <javascript:>> wrote:
> > Tatu,
> >
> > Thank you for your response.
> >
> > My goal was to delegate some deserialization inside of my custom
> > deserializer to the Jacksons default deserializer, which is aware of
> other
> > registered deserializers for a given type.
> > So in my example, I wanted to pass on the Jail treenode the Jacksons
> default
> > deserializer and let Jackson figure out which other registered
> deserializer
> > to use.
>
> Then you need to find the deserializer through
> `DeserializationContext`, giving target type.
> This can be done either from `deserialize()`, or from initial call to
> `resolve()`.
>
> -+ Tatu +-
>
> >
> >
> >
> > On Friday, August 18, 2017 at 4:38:24 PM UTC-4, Tatu Saloranta wrote:
> >>
> >> 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] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > 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.