2

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.

2 Answers 2

3

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");

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

1 Comment

I'm not totally understanding your answer. Can you give more detail like Jigar Joshi did? What is the context of using .addImplicitCollection ?
2

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

3 Comments

@Jinesh it can be , but from the XML you have given there is no need to take it as Object , String will do it for you
That did not work. the alias that i am configuring is xstream.aliasField("show", Show.class, "show");
com.thoughtworks.xstream.converters.ConversionException: show : show ---- Debugging information ---- message : show : show

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.