Override java.util.Date conversion in Simple XML

DeborahFerley

New Member
I'm trying to process some XML with Simple that contains a non-conforming date format.The standard \[code\]DateTransform\[/code\] converter cannot parse the date correctly, so I'm looking to write my own implementation. My domain object looks like this:\[code\]@Rootpublic class GuideProgramme { @Attribute private Date start; @Attribute private Date stop;}\[/code\]I've written a custom \[code\]Convertor\[/code\] as detailed in the documentation, note it does not actually convert the value yet:\[code\]public class MyCustomDateConverter implements Converter<Date> { @Override public Date read(InputNode node) throws Exception { System.out.print("HERE") return new Date(); } @Override public void write(OutputNode node, Date date) throws Exception { }}\[/code\]I use the RegistryStrategy to explicitly bind the convertor in Simple (just to make sure the problem is not due to some annotation discovery issue):\[code\]Registry registry = new Registry();Strategy strategy = new RegistryStrategy(registry);Serializer serializer = new Persister(strategy);registry.bind(Date.class, MyCustomDateConverter.class);MyOutput response = serializer.read(MyOutput.class, input);\[/code\]When I execute above code, Simple just ignores my custom converter and uses the built-in \[code\]DateTransform\[/code\], which consequently fails with an "Unparseable date" message. My "HERE" test message is never displayed. How do I get Simple to use my convertor instead of the built-in one?
 
Back
Top