Search code examples
xstream

xstream convert empty attributes to null values


I'm using XStream to serialize/deserialize objects. Is it possible to convert serialized empty attribute values to null object values? For example if I have

<tag number="">...</tag>

I want to have number field in my object assigned to null.


Solution

  • Yes, you can.

    Have a look at XStream.registerConverter(Converter). In your converter, you can tell XStream what steps to take to convert from and to XML. There are plenty of useful implementations already available, maybe one even suits your purpose.