On Fri, May 31, 2019 at 3:29 PM 遗迹 <[email protected]> wrote:
> Hello,
>
> I create a deserializer for match corret subclass of abstract class.
>
> I register the deserializer for `InputMessageContent`.
> But when I call `jp.getCodec().readTree<JsonNode>(jp)` in
> `deserializer(JsonParser jp, DeserializationContext ctxt)`.
> It return the parent element which contains `InputMessageContent`.
>
> But If I call jp.nextToken() before, it will works.
>
> It's says:
>
> input:
> {"foo": {"a": "value", "b": "something"}}
>
> type define:
> class Foo{
> InputMessageContent foo;
> }
>
> @JsonDeserialize(using = InputMessageContentDeserializer.class)
> class InputMessageContent{
> String a;
> String b;
> }
>
> Output:
> jp.getCodes().readTree(jp).toString()=="{"foo": {"a": "value", "b": "
> something"}}"
> //I wish it should be "{"a": "value", "b": "something"}" <--- If I call
> jp.nextToken() before.
>
>
>
> In fact, I'm use Kotlin for this.
> The source code is long:
> https://paste.ubuntu.com/p/X2qSNGSQGp/
>
>
I agree: it should not be necessary to call `nextToken()` at that point.
But instead of
`jp.getCodec().readTree<JsonNode>(jp)`
I would just call
`jp.readValueAsTree()`
Not sure if that makes a difference. Also make sure to use a new version of
`jackson-databind` and `jackson-core`.
I hope this helps,
-+ 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/CAGrxA27XEQD8LtuFzYw1WqWETxbnU83ss_y_R%2B-8pBouV457Qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.