Search code examples
androidxstream

How to generate/ serialize a Xml using XStream?


I have a BO class which is not annotated for XStream library and i have to serialize a xml from this class with only two fields.

do i need to specify all other field in omit ? or can i specify which fields are needed to serialize?


Solution

  • If you want to do it using normal way, you should specify all fields as omitted. If you take a look at http://jira.codehaus.org/browse/XSTR-569 there was a ticket about it from long time ago that was closed as 'not a bug' ('XStream is a serialization tool, not a data binding tool').

    There is another question which shows some workarounds to get it working the way you want, though it might not be so clean to do it, since the idea of XStream is not to work this way. Take a look: How to make XStream skip unmapped tags when parsing XML?