Is it possible to use recursion with simple framework to deserialize highly nested xml structure?
Below is sample xml structure that can contain n-levels of Format element lists and sub-list of either inline or element Field:
<request>
<Format name="Transaction" prefix="BitMap" >
<Format name="Bit1" prefix="Bit1">
<Field name="field1a " length="3"/>
<Field name="field1b" length="3"/>
</Format>
<Format name="Bit2" prefix="Bit2">
<Format name="Bit21" prefix="Bit21">
<Field name="field21a" length="3"/>
<Field name="field21b" length="3"/>
</Format>
</Format>
<Format name="Bit3" prefix="Bit3">
<Format name="Bit31" prefix="Bit31">
<Field name="field31a" length="3">
<Mask with="#"/>
</Field>
</Format>
<Format name="Bit32" prefix="Bit32">
<Format name="Bit321" prefix="Bit321">
<Field name="field321a" length="3">
<Mask with="#"/>
</Field>
</Format>
</Format>
</Format>
</Format>
</request>
Object classes:
Request
@Root(strict = false)
public class Request {
@ElementList(required = false)
public ArrayList<Format> Format;
}
Format
@Root(strict = false)
public class Format {
@ElementList(required = false)
public ArrayList<Format> Format;
@Attribute(name="name", required=false)
private String name;
@Attribute(name="prefix", required=false)
private String prefix;
@ElementList(entry="Field", inline = true, required = false)
private List<Fields> Field;
}
Field
@Root(name="Field",strict = false)
public class Fields {
@Element(name="Field", required=false)
private String Field;
@Attribute(name="name", required=false)
private String name;
@Attribute(name="length", required=false)
private String length;
@Element(required = false)
private Mask Mask;
static class Mask{
@Attribute(required = false)
private String with;
}
}
Without converter annotation, XML can be deserialized up to 2nd level only so I began looking at recursion.
I'm trying to do it via converter class but during traversal of field nodes, node.getnext() seems not able to see the next inline Field within the same parent node. I can only get the first inline Field
2 weeks into this and I'm out of ideas. Any help will be greatly appreciate by this Java newbie.