Reputation: 2141
I want to convert below XML to objects. I
<authentication>
<name>Reese Rideout</name>
<shows type="array">
<show>stage</show>
<show>youtube</show>
</shows>
</authentication>
I have Authentication class with List<Show> shows. I believe I will need to use the array converter. However, I do not understand how to use it and am not finding any documents.
Kindly suggest how could I parse this into my object graph.
Upvotes: 2
Views: 4563
Reputation: 2141
This is how I fixed this:
xstream.alias("shows", Shows.class);
xstream.alias("show", String.class);
And also set the Shows.shows
field as an implicit collection: xstream.addImplicitCollection(Shows.class, "shows");
Upvotes: 3
Reputation: 240860
For
<authentication>
<name>Reese Rideout</name>
<shows type="array">
<show>stage</show>
<show>youtube</show>
</shows>
</authenticatoin>
you can have
class Authentication{
String name;
List<Show> shows;
}
class Show{
List<String> show;
}
You will have to use aliasing
xstream.alias("authentication", Authentication.class);
xstream.alias("Show", Show.class);
Upvotes: 2