0

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;
}

1 Answer 1

1

The simplest way to solve this is to use multiple elements always. Just remove code related to single elements.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.