Declarative XML & # 8594; POJO conversion

I need to write a process (in Java) that periodically removes the URL, reads the returned XML document, and stores this data in the database. This data is also used by my application, so I modeled it as a POJO with a Hibernate mapping.

I can parse the XML and then create the appropriate POJOs, but I was looking for a simpler declarative approach. What libraries are available that can accept input configuration and create POJOs from an XML document?

+4
source share
5 answers

Another alternative might be JiBX

Also, although you said you didn't want to parse XML, can XPath be a very concise way of retrieving content that interests you?

+4
source

JAXB can automatically create classes based on an XML schema (if you have one for the XML source). At run time, it can convert an XML document to a POJO representing XML. It is declarative in that you can customize the display of the schema for the class a little.

If I understand your task correctly, this is pretty much used by the JAXB use case (although it can do other things). This is part of Java 1.6 (maybe 1.5 too?), In packages: javax.xml.bind. *

+2
source

You can use XStream to deserialize XML and map it directly to POJOs displayed by Hibernate.

Greetings.

+1
source

With Hibernate, you can directly map an XML table. This is an experimental feature. Check here http://www.hibernate.org/hib_docs/v3/reference/en-US/html/xml.html

0
source

EclipseLink JAXB (MOXy) has extensions for converting JPA objects to XML (JPA objects have things like built-in identifier classes, lazy loading and complex keyword relationships that require special handling), I don't know of any other OXM solution that doing this.

For more information see

0
source

All Articles