bdecaf bdecaf - 1 year ago 75
Java Question

How would I use XStream to produce smaller output for simple maps?

I serialize the data of my application with xstream. Since it should be read by other applications - or even viewed manuall I'd like to touch up the XML.

I have big maps of very simple types like

. I want to make my output more compact for these. Say from:


<entry key="56">38.0</entry>

Unfortunately my experiments using
this.aliasAttribute(Entry.class, "key", "key")
fail with null pointer exception.

And I'm having problems to understand how I would write/register an
that would handle
but keeps the default behaviour for

Maybe you can point me to a solution, thanks.

maybe the stacktrace can give some information.

at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldOrNull(
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.field(
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.getField(
at com.thoughtworks.xstream.mapper.AttributeMapper.addAttributeFor(
at com.thoughtworks.xstream.XStream.useAttributeFor(
at com.thoughtworks.xstream.XStream.aliasAttribute(
at myproject.XstreamSerializer.<init>(

Answer Source

There is a TreeMapConverter in XStream
May be it can help you out.
You can further read about this here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download