On Sun, Jan 16, 2022 at 5:23 PM Juan Rada <[email protected]> wrote:
>
> Hello folks
>
> I am using jackson xml  to deserialize an array of elements of diferent types 
> like.
>
> <array>
>      <type1>...content-1a...<type1/>
>      <type2>...content-2...<type2/>
>      <type1>...content-1b...<type1/>
> <array>
>
> The problem is that when using tree model 
> (JsonParser#readValueAsTree<TreeNode>) in my custom deserializer, this is 
> transformed into json and it becomes
>
> {
>     "array" :  {
>         "type1": [{content-1a}, {content-1b}]
>         "type2": {content-2}
>     }
> }
>
> As you notice order information is lost.  I am aware (as it said in 
> documentation) that tree modeling has some limitation but I am wondering if 
> there is any suggested workaround. Note that I am using custom serialization 
> register using JacksonXmlModule.addDeserializer and not annotation base 
> approach.

There is no way to represent such content as JsonNode without losing
some of the ordering information, unfortunately, as duplicate keys are
not allowed.
This is indeed a limitation that cannot be overcome with that model.

One thing that you could do is to instead define a POJO with setters
to match "type1" and "type2": setters will get called
in document order and you can retain ordering using whatever data
structure you want.

Or, alternatively, you could possibly sub-class one of `Map`
implementations (or define a completely custom one), override its
`put()` method which should also be
called for properties, in order. Within that method you could do
something different than call "super.put()".

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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/5b129782-c3c2-4bb3-b9c8-8222d18339c0n%40googlegroups.com.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10gkYCmDUi%3Dh1G5f4OCFFAHXkn8oKuKjPDWKo%2BnTiG5OKg%40mail.gmail.com.

Reply via email to