I think this is then a structure that is not supported by Jackson at this point.

I don't know if it would be possible to try combine elements; the
problem is that polymorphic type being written results in one element,
and then POJO itself results in the other.

-+ Tatu +-

On Fri, Apr 14, 2017 at 7:11 AM,  <ndo...@mindbridge.ai> wrote:
> hi Tatu,
>
> I just tried your recommendation and it gave me similar results as before:
>
> <Zoo>
>   <name>Samba Wild Park</name>
>   <city>Paz</city>
>   <animals>
>     <lion>
>       <name>Simba</name>
>       <sound>Roar</sound>
>       <type>carnivorous</type>
>       <endangered>true</endangered>
>     </lion>
>   </animals>
>   <animals>
>     <elephant>
>       <name>Manny</name>
>       <sound>trumpet</sound>
>       <type>herbivorous</type>
>       <endangered>false</endangered>
>     </elephant>
>   </animals>
> </Zoo>
>
> Notice the <animals> tag doesnt wrap around both elements but around each,
> instead.
>
>
> On Friday, April 14, 2017 at 10:04:17 AM UTC-4, ndo...@mindbridge.ai wrote:
>>
>> Hi Tatu,
>>
>> Thanks for responding. I think I have a similar setup here:
>> https://groups.google.com/forum/#!topic/jackson-user/QN3bVAgFluU. But you'll
>> notice that the object gets wrapped twice in serialization and expects the
>> same for deserialization. Instead of getting <result><lion></lion></result>,
>> I get <result><result><lion></lion></result</result>. This is with latest
>> stable release (2.8.6).
>>
>> On Friday, April 14, 2017 at 1:55:08 AM UTC-4, Tatu Saloranta wrote:
>>>
>>> Please note that Jackson does not guarantee that it can support all kinds
>>> of XML.
>>> It does aim to be able to deserialize content it serializes: so if you
>>> can find a way to serialize content in certain XML structure, it should be
>>> readable. But there are other structures that are not.
>>>
>>> In this case we would have POJO with `animals` property which is a
>>> collection type, and would have to be "unwrapped" (configure to use
>>> unwrapped list, or annotate).
>>> Elements are polymorphic, so need `@JsonTypeInfo`, and type id inclusion
>>> looks like `As.WRAPPER_OBJECT`.
>>> I am not sure if that would exactly as presented, but it'd be something
>>> like:
>>>
>>> public class Result {
>>>   @JacksonXmlElementWrapper(useWrapping=false)
>>>   public List<Animal> animals;
>>> }
>>>
>>> @JsonTypeInfo(use=Id.NAME, include=As.WRAPPER_OBJECT)
>>> public abstract class Animal {
>>> }
>>>
>>> @JsonTypeName("cat")
>>> public class Cat extends Animal {
>>>   public String name;
>>> }
>>>
>>> -+ Tatu +-
>>>
>>>
>>> On Thu, Apr 13, 2017 at 9:09 PM, <ndo...@mindbridge.ai> wrote:
>>>>
>>>> Hi,
>>>>
>>>> How would I go about deserializing this array of mixed elements?
>>>>
>>>> <result>
>>>> <animals>
>>>> <cat><name>foo</name></cat>
>>>> <dog><name>pop</name></dog>
>>>> <cat><name>fluff</name></cat>
>>>> <giraffe><name>dodo</name></giraffe>
>>>> </animals>
>>>> </result>
>>>>
>>>> I haven't discovered a way yet :(
>>>>
>>>> --
>>>> 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 jackson-user...@googlegroups.com.
>>>> To post to this group, send email to jackso...@googlegroups.com.
>>>> 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 jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to