Reputation: 1041
I want to deserialize different sets of XML serialized data into one class (not at the same time) using SimpleXML.
All of the datasets have a root class of <body/>
, but different subclasses. Some have one element of <prediction>
, other multiple elements of <prediction>
. Same for <route>
. This is the code I currently use, but it gives me an error of type PersistenceException
("Duplicate annotation").
What would be the simplest way to solve this? Any help would be appreciated.
@Root(name = "body", strict = false)
class NextBusAPIResult {
@Attribute(name = "copyright")
public String Copyright;
@Element(name = "predictions", required = false, type = Predictions.class)
public Predictions Predictions;
@ElementList(name = "predictions", required = false, inline = true)
public List<Predictions> PredictionsForMultiStops;
@Element(name = "route", required = false, type = RouteInfo.class)
public RouteInfo RouteInfo;
@ElementList(name = "route", required = false, inline = true)
public List<RouteSchedule> RouteSchedules;
}
Upvotes: 0
Views: 113
Reputation: 4601
The simplest way to solve this is to use multiple elements always. Just remove code related to single elements.
Upvotes: 1