Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice for Serialize/Deserialize from Java to XML

What is the most appropriate way to serialize Java Classes to XML? I tried JAXB, but it has issues with Interfaces and Generics. What solution is least intrusive but scalable?

like image 313
mbx Avatar asked May 25 '10 09:05

mbx


People also ask

What is the correct way of using XML deserialization?

As with the CreatePo method, you must first construct an XmlSerializer, passing the type of class to be deserialized to the constructor. Also, a FileStream is required to read the XML document. To deserialize the objects, call the Deserialize method with the FileStream as an argument.

Which items should never be serialized Deserialized?

Examples of sensitive data that should never be serialized include cryptographic keys, digital certificates, and classes that may hold references to sensitive data at the time of serialization.

Which two can be considered good practices for serializing Java objects?

More serialization best practicesNo static or transient fields undergo default serialization. Extendable classes should not be Serializable, unless necessary. Inner classes should rarely, if ever, implement Serializable.

Is Java serialization fast?

Fast-serialization (FST) is a Java serialization framework that is fully compatible with the JDK serialization protocol. Its serialization speed is ten times faster than JDK Serializable, but the byte size is only 1/3 the size of JDK Serializable. The latest FST version is 2.56.


1 Answers

I've always had positive experiences with XStream:

http://x-stream.github.io/tutorial.html#to-xml

As you can see, it's simple to use.

I haven't actually used XStream with Generics (I've only ever used it for simple JavaBean type classes), but Google seems to suggest it handles them without problems. e.g. http://techo-ecco.com/blog/xstream-spring-ws-oxm-and-generics/

like image 73
laher Avatar answered Sep 30 '22 12:09

laher