Deserializing XML with Jackson and optional child tags

Viewed 79

I'm trying to deserialize a XML with nested tags, but i'm facing a problem when the wrapper is comming with no child tags.

Actual Java block code:

    @JacksonXmlElementWrapper(localName = "foo")
    @JacksonXmlProperty(localName = "bar")
    private List<String> bar;

Example:

<row>
 <foo>
  <bar>test</bar>
  <bar>test2</bar>
 </foo>
</row>

In the above example, my tests are running fine. Debugging the result of List<String> bar is returning [test,test2]

The problem is that i'm facing the following exception when my application is receiving a XML with no tag at all (I must accept that because it's comming from a web server outside my domains), like this:

<row>
 <foo>

 </foo>
</row>

Cannot deserialize instance of 'java.util.ArrayList' out of VALUE_STRING token

through reference chain: Result["row"]->java.util.ArrayList[0]->ROW["foo"])

How can i attend this two ways of deserialize this XML? With and without < bar > ?

0 Answers
Related