Search This Blog

Showing posts with label jaxb. Show all posts
Showing posts with label jaxb. Show all posts

Friday, 9 August 2013

Custom Marshaling With JAXB

Consider the below class:
@XmlRootElement
public class Person {
   private String name;
   private BigDecimal weight;
   private Date dob;

   // getters and setter
}
If we were to marshal a Person instance the generated XML would be:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
   <dob>2013-06-15T13:01:35.420+05:30</dob>
   <name>Test</name>
   <weight>65.876499999999992951416061259806156158447265625</weight>
</person>
The value for dob is a little complex. Could we change this to a more suitable value ?

Tuesday, 30 July 2013

Order and Occurence indicators in xsd

Unlike simple types, complex types can have nested elements. Consider the below complex type:
<element name="address">
   <complexType>

Monday, 24 June 2013

Inheritance in xsd

In the last post we were able to map elements which included attributes. An alternative way of representing elements is to nest them. Consider the below schema definition:

Thursday, 16 May 2013

More on Complex Types

In the last post we were able to map complex xml elements to classes. However it is recommended to build complex types and associate them to elements.

Wednesday, 15 May 2013

JAXB and Complex types

In the previous post we saw how JAXB generated JAXBElement instances from simple types. Simple types however are just that - simple (!!!)
We often need our elements to allows attributes, include child elements etc. These cannot be achieved using simple types. We need to create complex types for the same.

Monday, 13 May 2013

JAXB and simple elements

In the past few weeks I have been working with web-services. So exposure to xml and xsd was inevitable. I had used xsd a while back and so I needed a revision of some of those topics. I decided to do a quick summary of some of the options available in xsd and how JAXB works with them