When using XStream to serialise Java object into XML, alias name with undercore (_) will get duplicate. For example, "first_name" will be serialised as "first__name".
The reason is explained in their FAQ and the workaround is to provide your own XmlFriendlyReplacer. However, it do not give any example. So here is the example:
// replace $ with "ddd"
// replace underscore with underscore
XmlFriendlyReplacer replacer = new XmlFriendlyReplacer("ddd", "_");
XStream xstream = new XStream(new DomDriver("UTF-8", replacer));
21 comments:
Excellent Thiam - just what I was looking for.
Many thanks!
you the man! that worked great
Perfection! thanks a lot
To use the default XPP Driver, though, you want to change it to:
XStream xstream = new XStream(new XppDriver(replacer));
Good result! Thanks very much for posting.
thank you so much... You can't imagine how in pain I was planning to go...
thank you so much... You can't imagine how in pain I was planning to go...
Instant solution. Many thanks
hey, so much thanks! great post!
perfect!
Thanks Thiam - works like a charm
It was great. Thanks
It was great. Thanks
very nice example 10x
superb work done, Thanks
Does not work for me... I get double underscore with setting a modified XmlFriendlyReplacer to XStream object. Using 1.3.1 of XStream.
Thanks a tonne !
worked for me, in version 1.4.2, thank you
Thx
thanks, but doesn't work on 1.3.1
Post a Comment