xstream api in java throwing error in xml parsing

31 views Asked by At

I have used xstream api to unmarshall the xml message and code is always failing

Code block:

        XStream xStream=new XStream();
        xStream.processAnnotations(ProjectDescription.class);
        xStream.processAnnotations(Projects.class);
        xStream.ignoreUnknownElements();
        System.out.println("Unmarshalling begins...");
        ProjectDescription appDesp = (ProjectDescription)         xStream.fromXML("checkxml.xml");

Entity class

** ProjectDescription.class:**


@XStreamAlias("projectDescription")
public class ProjectDescription {
    @XStreamAlias("name")
    private String name;

    @XStreamAlias("comment")
    private String comment;

    @XStreamImplicit
    private List<Projects> projects = new ArrayList<Projects> ();




}

Project.class:

@XStreamAlias("projects")
public class Projects {
     @XStreamImplicit
     private List<String> project= new ArrayList<String>();


}

Sample XML:

<projectDescription>
    <name>SimpleApp</name>
    <comment></comment>
    <projects>
        <project>Sampleshare</project>
        <project>Sampleshare2</project>
        <project>Samplestatic</project>
    </projects>
</projectDescription>

It is erroring out with message:

Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not C (position: START_DOCUMENT seen C... @1:2)

Can somebody guide me whereI am going wrong?

I have tried both DOM parser and XStream api but same sample message stated above is working for DOM and not XStream.

0

There are 0 answers