0

I am using XStream to serialize Java objects to XML. Is it possible to customize XStream so that when it serializes an object it inserts an attribute in the root XML element?

Let's say I have

class A{
 int foo = 1;
}

I want XStream to serialize instances of A to look like:

<A type="text/xml">
 <foo>1</foo>
</A>

Where the attribute text/xml is automatically added to the root element.

My use case is serializing my java object and insert it as the content element inside Atom entry documents. The end result would look like:

<feed>
<content type="text/xml">
<foo>1</foo>
</content>
</feed>

I do not require being able to unmarshall the feed. I need a generic solution that is agnostic to the class of the object I am serializing.

Can I achieve this with XStream?

1 Answer 1

1

The only way are the the XStream.useAttributeFor(...) methods.

This would force you to configure XStream for each object type you are using though, thus not agnostic.

So I don't think XStream is the tool you need.

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

Comments

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.