Xml Serializer and Deserializer with object?

– RSR Jan 29 at 11:21 It serializes an object to XML and deserializes an XML back to an object. – Darin Dimitrov Jan 29 at 11:25.

There are many libraries to do this job (serialize and deserialize objects), one of the simplest in use is XStream, here is example of using: Person joe = new Person("Joe", "Walnes"); joe. SetPhone(new PhoneNumber(123, "1234-456")); joe. SetFax(new PhoneNumber(123, "9999-999")); Now you can simple run String xml = xstream.

ToXML(joe); and the result is: Joe Walnes 123 1234-456 123 9999-999 To get object back run Person newJoe = (Person)xstream. FromXML(xml); Another possible option could be JAXB, from wikipedia: Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e.To unmarshal XML back into Java objects.

In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to xsd. Exe and xmlserializers in .

Net Framework. But as for me, most tasks can be done with XStream, which lightweight and more easy (imho).

In Java there's XMLEncoder Your methods will look something like: public static T convertToObject(Class objectType, String xml) { XMLDecoder decoder = new XMLDecoder(new ReaderInputStream(new StringReader(xml))); T result = (T) decoder.readObject(); decoder.close(); return result; } public static String convertToString(Object object) { StringWriter sw = new StringWriter(); XMLEncoder encoder = new XMLEncoder(new WriterOutputStream(sw)); encoder. WriteObject(object); encoder.close(); return sw.toString(); } (Note that ReaderOutputStream is from apache commons-io).

I can't use xml encoder or decoder for objecttype as argument – RSR Jan 29 at 11:22 @RSR why not?.. – Bozho Jan 29 at 13:03 becoz it doesn't accepts the Typeof() and Type datatypes while passed from other functions. – RSR Feb 1 at 7:58 @RSR I didn't understand that comment. What is Typeof?

And what is "Type datatypes" – Bozho Feb 1 at 8:18 I had displayed full code above which you refer and see that typeof() used to refer class which contains xmlelement attributes while serializing and Type used to access class object – RSR Feb 2 at 6:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions