x-stream / xstream

Serialize Java objects to XML and back again.
http://x-stream.github.io
Other
749 stars 227 forks source link

how both text and sub tags exist #341

Closed lixun027 closed 1 year ago

lixun027 commented 1 year ago

I want to implement an XML where both text and sub tags exist. How should my class be written?

<user name="Joker">
        <age>16</age>
        Manhattan, New York
</user>

image

I've looked at all the annotations and I can't find any annotation like @XStreamText. Please teach me, How can I do that

joehni commented 1 year ago

Sorry, this case is not supported. XStream is in first line Java to XML (and back). So a class member is either a value (resulting in a value of a tag or attribute) or some object that is mapped to another tag, but never both.

lixun027 commented 1 year ago

This requirement meets the standards of XML, and I have used both jaxb and fastXML, both of which support the above implementation. But they cannot be used in Android. Are you considering implementing this feature in Xstream in the future. Not only me, but also others will encounter this need.

joehni commented 1 year ago

As said, XStream has a different purpose. It is a tool to persist any kind of Java object in a textual format; this implies that XStream can read XML it has created (and it offers quite some possibilities to tweak the written XML), but it was not made to read any arbitrary XML structure and turn it into Java objects.