Questions tagged [oxm]

Object/XML Mapping, or O/X mapping for short, is the act of converting an XML document to and from an object. This conversion process is also known as XML Marshalling, or XML Serialization.

Some of the benefits of using Spring for your O/X mapping needs are:

Ease of configuration.

Spring's bean factory makes it easy to configure marshallers, without needing to construct JAXB context, JiBX binding factories, etc. The marshallers can be configured as any other bean in your application context. Additionally, XML Schema-based configuration is available for a number of marshallers, making the configuration even simpler.

Consistent Interfaces.

Spring's O/X mapping operates through two global interfaces: the Marshaller and Unmarshaller interface. These abstractions allow you to switch O/X mapping frameworks with relative ease, with little or no changes required on the classes that do the marshalling. This approach has the additional benefit of making it possible to do XML marshalling with a mix-and-match approach (e.g. some marshalling performed using JAXB, other using XMLBeans) in a non-intrusive fashion, leveraging the strength of each technology.

Consistent Exception Hierarchy

Spring provides a conversion from exceptions from the underlying O/X mapping tool to its own exception hierarchy with the XmlMappingException as the root exception. As can be expected, these runtime exceptions wrap the original exception so no information is lost.

42 questions
12
votes
1 answer

jaxb: strange class cast exception on enum list

I am using jaxb to generate java classes from an xsd file. The xsd contains a definition of an element of which the content is a list of constants defined in the same xsd as enumeration. When the classes are generated using the JAXB reference…
A4L
  • 17,353
  • 6
  • 49
  • 70
9
votes
2 answers

Mapping XML to an object in Java

Suppose I have a class called Test, like this public class Test { private String testId; private String description; private String department; public Test() {} public Test(String id,String des,String dpt) { …
Waqas Ali
  • 1,642
  • 4
  • 32
  • 55
8
votes
2 answers

JAXB HashMap unmappable

I want to convert a HashMap in a POJO class to XML. I tried using the XmlAdapter but it results in only the key and value pairs of the HashMap being the attributes of the XML Elements. I need the Key to be the Element itself and the value of the…
Anand
  • 1,791
  • 5
  • 23
  • 41
7
votes
2 answers

JAXB - Creating modules for reuse

Does JAXB support modular code generation? Most of my background is with JibX for XML marshalling, but for legacy reasons our firm is using JAXB. One feature that was available for JIBX was modular code generation. Say I have a main schema but I…
Roy Truelove
  • 22,016
  • 18
  • 111
  • 153
6
votes
4 answers

What is the best Java OXM library?

Even though I've been a developer for awhile I've been lucky enough to have avoided doing much work with XML. So now I've got a project where I've got to interact with some web services, and would like to use some kind of Object-to-XML Mapping…
bpapa
  • 21,409
  • 25
  • 99
  • 147
4
votes
2 answers

Grouping properties using JAXB annotations

I have a class Product with the following properties: name, dateCreated, createdByUser, dateModified and modifiedByUser, and I'm using JAXB marshalling. I'd like to have output like this: ...
user41871
4
votes
2 answers

Convert Java object to XML

I am trying to convert a Java object inside of a Java library to an XML file. However, I got this problem: A a = new A(); // initializing for a JAXBContext jc = JAXBContext.newInstance("libraryA.A"); Marshaller marshaller =…
olidev
  • 20,058
  • 51
  • 133
  • 197
4
votes
1 answer

Jibx - how to unmarshal/marshal tag with value and attribute?

12 72 Sorry Guys, I did not meant to be lazy. Ok Here is the question: I have xml structure with above block of xml which some tags has both value and attribute…
Gord
  • 41
  • 4
4
votes
1 answer

distinct XML mapping/binding on the same Java object

I have a Java application interoperable with several others information systems A same object could be mapped in differents XML files according to the information system targeted My question is : Is there a Java solution to perform serveral XML…
kwisatz
  • 1,266
  • 3
  • 16
  • 36
4
votes
6 answers

Spring: OXM error when unmarshalling XML string (castor)

I am doing Spring Integration project. I'd like to publish XML string to one channel and receive Java object in other channel, via unmarshalling transformer. In my Spring config I am using these channels and beans: