I'm trying to deserialize this snippet of XML in Java:
<anime id="16986">
<info type="Picture" src="http://~.jpg" width="141" height="200">
<img src="http://~" width="141" height="200"/>
<img src="http://~" width="318" height="450"/>
</info>
<info type="Main title" lang="EN">Long Riders!</info>
<info type="Alternative title" lang="JA">ろんぐらいだぁす!</info>
</anime>
The problem I'm running into is that the info
element either can have an inline list of img
's or it can just contain text. I was thinking of treating info
as an @Element
in my AnimeHolder class, but I can't have duplicate annotations. I would also like to access the lang
attribute of info to check if it is EN or JP.
I am using these classes to hold the deserialized data:
@Root(name="anime", strict=false)
public class AnimeHolder {
@Attribute(name="id")
private String ANNID;
@ElementList(inline=true)
private List<InfoHolder> infoList;
public String getANNID() {
return ANNID;
}
public List<InfoHolder> getInfoList() {
return infoList;
}
}
and for the info items:
@Root(name="info", strict = false)
public class InfoHolder {
@ElementList(inline=true, required = false)
private List<ImgHolder> imgList;
@Attribute(name = "lang", required = false)
private String language;
public List<ImgHolder> getImgList() {
return imgList;
}
}