Deserializing XML to Object
I have a xml file, which is not serialized using XStream.
It may be in any custom but fixed format, 开发者_JAVA技巧How to use XStream or any efficient api to de serialize it to Object.JAXB fits your needs. See here:
https://jaxb.dev.java.net/tutorial/
or here:
http://download.oracle.com/javaee/5/tutorial/doc/bnbay.html
I believe you need to implement your own Converter, see this tutorial
Edit: There are surely other ways (read: other packages) to sort this out, but in your question you have mentioned that you wanted to use XStream, hence my reply, and the link to tutorials there.
You could use the @XmlPath extension in MOXy JAXB to map your object model to any XML document without worrying about writing converters. You can also use the externalized metadata format to apply multiple mappings to your object model:
For more information see:
- http://bdoughan.blogspot.com/2010/09/jaxb-xml-infoset-preservation.html
- http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML
The most performant XML serializer is Simple. Its both faster and more memory efficient than JAXB. Its also much easier to use. Everything can be done via annotations, you do not have to deal with XML directly.
精彩评论