PDA

View Full Version : Converting from POJO to XML?



bjorntj
Sep 11th, 2006, 04:12 AM
We have a complex domain model for our project and we are thinking about making certain functions available using webservices...
So I was just wondering if anyone knew of any application we can use to convert our object (containing Set, List, etc) into xml that the webservice can use?


Regards,

BTJ

Arjen Poutsma
Sep 11th, 2006, 10:27 AM
The general term for it is XML marshalling or XML binding, and there are a lot of tools which can do that: JAXB, Castor, JIBX, XMLBeans...

bjorntj
Sep 11th, 2006, 10:54 AM
The general term for it is XML marshalling or XML binding, and there are a lot of tools which can do that: JAXB, Castor, JIBX, XMLBeans...

I have looked at most of them, but they don't seem to be able to convert other than ordinary types (not List and Sets, etc) or am I mistaken?

BTJ

beemsoft
Oct 17th, 2006, 07:16 AM
I have looked at most of them, but they don't seem to be able to convert other than ordinary types (not List and Sets, etc) or am I mistaken?

BTJ
In my experience, these frameworks have no problems with List types.

benethridge
Oct 18th, 2006, 11:42 AM
This is my experience as well, i.e. no problem in this regard using both JAXB and Castor. They eliminate a LOT of the grunt work. In the "old days" we had to do all the grunt work using the DOM api.

Ben

Arjen Poutsma
Oct 18th, 2006, 01:40 PM
This is my experience as well, i.e. no problem in this regard using both JAXB and Castor. They eliminate a LOT of the grunt work. In the "old days" we had to do all the grunt work using the DOM api.


Well, there are some finesses you can't express with XML marshalling solutions. Java and XML are different beans, just as Java and SQL are. Sometimes, it makes more sense to use JDBC instead of Hibernate, and sometimes, it makes more sense to use DOM instead of JAXB.

benethridge
Oct 18th, 2006, 02:18 PM
I agree. Like using a chain saw versus a Dremel scroll saw. Both good tools, if used as intended.

Ben

farrellr
Oct 18th, 2006, 02:30 PM
Or maybe a shovel vs. a spoon?

glenn2041
Dec 13th, 2006, 09:21 PM
I'm not sure if it will work via WS, but you can try Apache Betwixt (http://jakarta.apache.org/commons/betwixt/). This will makes easy work of transforming pojo's to xml.

Arjen Poutsma
Dec 15th, 2006, 07:02 AM
It looks like Betwixt doesn't have any XSD schema support. This makes it less usable for doing web services, similar to XStream, for instance.

Not that I don't like these approaches, there just are less suitable for WS.