I would like to know how I can implement optional attributes within XStream.
Here is the XML:
<AttributeValues>
<AttributeValue attributeId='id01' languageId='en'>20</AttributeValue>
<AttributeValue attributeId='id02'>99</AttributeValue>
<AttributeValue attributeId='id03' languageId='en'78</AttributeValue>
<AttributeValue attributeId='id04' languageId='en'>14</AttributeValue>
<AttributeValue attributeId='id05'>9</AttributeValue>
</AttributeValues>
After the parsing process, not every 'AttributeValue' item has a languageId
.
XStream sets such empty values to 'null'. But I would like to have it as an empty string "".
How do I implement this?
You can achieve your goal using custom
Converter
class.There will be a bit of guessing here since you haven't posted code for
AttributeValues
andAttributeValue
class. I will use following classes:AttributeValues
class:AttributeValue
class:And here is
AttributeValueConverter
class:Serialization:
Unserialization: