Tag Archives: JAXB

From Spring to Java EE 6


via From Spring to Java EE 6 | Java Code Geeks.

I recently worked on a quite complex project mixing many Java EE 6 technologies (such as JPA, JAXB, JMS, JTA, JAX-RS, etc…). For productivity and planning reasons, the prototyped application was designed as a standalone pure Spring application. When the development of the real application started, we re-challenged our initial choice (i.e. Spring v3) and analyzed the interest of switching to a Java EE 6 app server like GlassFish or JBoss.
This finally ended up in two major questions:

  • can we do in Java EE 6 everything we can do in Spring ?
  • can we do that as easy as in Spring?

Well, I would say that, globally, the answer is: yes we can !

How to converts Java Object to XML – JAXB Example.


via How to converts Java Object to XML – JAXB Example.

JAXB, stands for Java API for XML Binding or sometimes Java Architecture for XML Binding is a decade old technology to directly convert a Java object into XML document (marshaling) and back to XML file into Java object(unmarshalling). It uses combination of annotations and getters and setters to marshal Java object into XML. JAXB actually defines the behavior of a standard set of tools and interfaces that automatically generate Java class files from XML schema, remember JAXB is actually a framework and architecture, not an implementation. The package java.xml.bind provides a runtime binding framework for clients to marshal, unmarshal and validate XML file in Java. BTW, JAXB is not the only option to parse XML in Java, you can always use SAX or DOM parser or JAXP API to convert XML to Java object and vice-versa. If you want to learn more about XML processing in Java, I suggest to look at chapter 2 of Core Java Volume 2 By Cay S. Horstmann. This book covers not only DOM and SAX but also StAX parser and locating information with XPath.

JAXB Tutorial for Java XML Binding – The ULTIMATE Guide


via JAXB Tutorial for Java XML Binding – The ULTIMATE Guide (PDF Download).

Java offers several options for handling XML structures and files. One of the most common and used ones is JAXB. JAXB stands for Java Architecture for XML Binding. It offers the possibility to convert Java objects into XML structures and the other way around. JAXB comes with the JRE standard bundle since the first versions of the JRE 1.6.

The first specification of JAXB was done in March 2003 and the work process is tracked in the Java Specification Request 31:https://jcp.org/en/jsr/detail?id=31. In this specification request you can find a lot of information regarding the long life of JAXB and all the improvements that have been made.

Jaxb Parsing : Xml


via Jaxb parsing : xml – Tutorial SavvyTutorial Savvy.

  • JAXB is for converting java pojo to xml.
  • It Supports annotation too.
  • In jdk 1.6 and above it is aready package inside.
  • For less then jdk 1.6 , download from link:-

A JAXB Nuance: String Versus Enum from Enumerated Restricted XSD String


via Inspired by Actual Events: A JAXB Nuance: String Versus Enum from Enumerated Restricted XSD String.

Although Java Architecture for XML Binding (JAXB) is fairly easy to use in nominal cases (especially since Java SE 6), it also presents numerous nuances. Some of the common nuances are due to the inability to exactlymatch (bind) XML Schema Definition (XSD) types to Java types. This post looks at one specific example of this that also demonstrates how different XSD constructs that enforce the same XML structure can lead to different Java types when the JAXB compiler generates the Java classes.

The next code listing, for Food.xsd, defines a schema for food types. The XSD mandates that valid XML will have a root element called “Food” with three nested elements “Vegetable”, “Fruit”, and “Dessert”. Although the approach used to specify the “Vegetable” and “Dessert” elements is different than the approach used to specify the “Fruit” element, both approaches result in similar “valid XML.” The “Vegetable” and “Dessert” elements are declared directly as elements of the prescribed simpleTypes defined later in the XSD. The “Fruit” element is defined via reference (ref=) to another defined element that consists of a simpleType.

Spring Object to XML


Spring Object to XML

With this tutorial we shall show you how to convert Objects to xml and vice versa, using Spring’s Object/XML Mapping support. 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. Within the field of O/X mapping, a marshaller is responsible for serializing an object (graph) to XML. In similar fashion, an unmarshaller deserializes the XML to an object graph. This XML can take the form of a DOM document, an input or output stream, or a SAX handler.

Spring’s OXM can be used for a wide variety of situations. In the following example, we will implement the interfaces it provides to marshal the information of a simple Spring Bean as an XML file and then unmarshal the xml file back to an Object. We will use the Castor implementation, although there are other implementations, such as JAXBMarshaller, XMLBeansMarshaller, JibxMarshaller, XStreamMarshaller, as described in the Spring Framework reference. In addition, we will show you how to use Castor XML mapping framework through Spring. Castor XML mapping is an open source XML binding framework. It allows you to transform the data contained in a java object model into/from an XML document. By default, it does not require any further configuration, though a mapping file can be used to have more control over the behavior of Castor.

Our preferred development environment is Eclipse. We are using Eclipse Juno (4.2) version, along with Maven Integration plugin version 3.1.0. You can download Eclipse from here and Maven Plugin for Eclipse from here. The installation of Maven plugin for Eclipse is out of the scope of this tutorial and will not be discussed. We are also using Spring version 3.2.3 and the JDK 7_u_21.

Let’s begin,

Android XML Binding with Simple Framework


Android XML Binding with Simple Framework

XML is still important in the area of web services even though REST has gained significant attention lately. Exposed APIs via web services is the main reason I have to manipulate XML content in my Android applications. For that reason I need to parse XML documents even though it is a tedious procedure.

In the past, I showed you how to parse XML using the SAX approach and how to boost your Android XML parsing with XML Pull. Both these techniques work, but are rather boring since they qualify as “plumbing code”. In this tutorial I am going to show you how to perform XML binding in Android using the Simple framework.

XML data binding is quite popular in Java and there are multiple frameworks that allow binding. Solutions like JAXB and XStream are well established and heavily used. However, these libraries come with a large footprint, something that makes them inappropriate for use in the resources constraint world of mobiles. The good news is that there is a new kid on the block, the Simple framework. As its name implies, it strives to bring some simplicity in the bloated world of XML.

From the official Simple framework site: