how to unmarshal this with xstream?

DaRolla

Mitglied
hi,

I am using xstream with and without annotation, and it's pretty easy to use.

Right now I got a case I get nuts on.

Here's my XML:

[xml]<content>
<tag type="p">
...
</tag>
<tag type="p">
...
</tag>
<tag type="h">
...
</tag>
<tag type="p">
...
</tag>
</content>[/xml]

So content has a list of tags. A tag itself has the attribute type which can be p oder h. And tag has content. And this is the problematic part :(

Java:
@XStreamAlias("content")
public class Content {

        @XStreamImplicit
        public List<Tag> listTag = new ArrayList<Tag>();
}

@XStreamAlias("tag")
public class Tag {

        @XStreamAsAttribute
        public String type;

        public String tag;
}

Or without annotations:

Java:
xstream.alias("content", Content.class);
xstream.addImplicitCollection(Content.class, "listTag", Tag.class);

xstream.alias("tag", String.class);
xstream.useAttributeFor(Tag.class, "type");

But after unmarshalling the content.listTag.get(i).tag is always NULL where content.listTag.get(i).type is p oder h as expected.

Somehow its unmarshalling only the attribute but not the child node.

Who can help me on this?

Greetings and lots of thanks,
Marco Schmitz
 
Zuletzt bearbeitet von einem Moderator:


Schreibe deine Antwort... und nutze den </> Button, wenn du Code posten möchtest...

Ähnliche Java Themen

Neue Themen


Oben