The only documentation on XStream converters that I can find is on these two pages:
When XStream is parsing XML input, it uses a ConverterLookup (and by default, a DefaultConverterLookup) to lookup which converter to use by class. I’d like to configure my XStream mapper to use my own custom ConverterLookup, but only see a getConverterLookup() method, not a respective setter.
I have an instance where XStream is encountering a Date value in the XML, and returning using the respective DateConverter. I want it to use a different converter, which (I believe) means I need to set/register my own Converter impl. Just can’t figure out how to do this. Thanks in advance.
First of all your question is in fact two unrelated questions, I’ll try my best to answer them both.
Converters
To your second question regarding date conversion. Which in my mind seems to be the reason why you are here.
The basic way of adding your own converter is rather simple, the method
registerConvertershould give your a clue. If you are wondering how to implement aConverterI suggest you take a look at one of the many converters already provided by XStream. On an extra note I feel like I must mention the priority of converters.In other terms, given two converters accepting the same classes, the one who was added last will be used.
ConverterLookup
To answer how you can use your
ConverterLookupthere are two ways which may yield the same results, personally I would go for alternative 2.1) Overriding
getConverterLookup2) Using a
MapperIn this case I would keep the
DefaultMapperand instead implementMapperWrapper‘s for my new mappings. (Have a look atbuildMapperinside ofXStream.javato see some of the defaults) Initialize like this: