0

For example, how would form an object from XML written like this?

<name length="4">Ryan</name>

I would normally alias a class using an annotation to "name" and then have a length and a field for the name. However, this will not work because the second field has no name.

*Edit confusing wording

2 Answers 2

1

It has been a while since I used xstream (2+ years) but I do remember using converters to change the way that objects are serialized. Check out http://x-stream.github.io/converters.html. Also this tutorial, http://x-stream.github.io/converter-tutorial.html, has some examples with attributes down towards the bottom.

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

Comments

0

Why not use JAXB?

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

@XmlRootElement
public class Name {

    @XmlValue
    private String name;

    @XmlAttribute
    private int length;
}

1 Comment

Check out my blog post comparing JAXB & XStream: bdoughan.blogspot.com/2010/10/…

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.