0

I have the following xml. I want to create a Trade class with a list of row objects in it, however it seems like the only way that would work would be if there was some kind of "rows" wrapper object around my list in the xml. Which there isn't. I just get no String-argument constructor/factory method to deserialize from String value ('xyz')

@Data
    public class Trade{
    String attr1;
    Row[] row //same error if its a list
@Data
public class Row{
String blah1,blah2;
    }

<Trade attr1=x, attr2=y>
<row>
<blah1>xyz</blah1>
<blah2>xyz</blah2>
</<row>
<row>
<blah1>xyz</blah1>
<blah2>xyz</blah2>
</row>
</Trade>
Steve
  • 4,457
  • 12
  • 48
  • 89
  • You need to create a `Row` class that has the attributes you're looking for. You also might want to take a look at this https://stackoverflow.com/questions/14789302/parse-xml-to-java-pojo-in-efficient-way – Dan Aug 15 '19 at 20:36
  • I've got a row class as a subclass to Trade. Unfortunately, for it to work the way you're describing I'd need the "row" objects to be wrapped in a "rows" wrapper of some kind which they aren't. I can't just ignore Trade either because I need the attributes – Steve Aug 15 '19 at 21:23
  • 1
    Have `Trade` contain `List` instead of `Row[]`. Also, `Trade` should not be the parent to `Row` (it should not be it's subclass) – Dan Aug 16 '19 at 01:14
  • @Dan nice work! that did it They just had to be separate. – Steve Aug 16 '19 at 13:32

1 Answers1

0

Dan's comment above is correct, but I also needed to add

@JacksonXmlElementWrapper(useWrapping = false)

to the list.

Steve
  • 4,457
  • 12
  • 48
  • 89