XML / NOTES</>↗XML13 Aug 2012
The code snippet below show you how to convert POJO into XML file using JAXB. To do this we can pass the output file where we want the XML to be saved to the marshaller object. package org.kodejava.xml; import org.kodejava.xml.support.Track; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import java.io.File; public class JAXBObjectToXmlFile { public static void […]
XML / NOTES</>↗XML13 Aug 2012
In this code snippet you can learn how to convert or unmarshall an XML file into it corresponding POJO. The steps on unmarshalling XML to object begin by creating an instance of JAXBContext. With the context object we can then create an instance of Unmarshaller class. Using the unmarshall() method and pass an XML file […]
XML / NOTES</>↗XML13 Aug 2012
In this code snippet you will learn how to define the order of XML element generated by the JAXB API. To define the element order we need to use the @XmlType annotation in our POJO. This annotation propOrder attribute is where we define what element should come first and which element should be place at […]
XML / NOTES</>↗XML13 Aug 2012
In the following code snippet you will learn how to change the default root element name of the XML generated by the JAXB API. By default, the name of the class is use as the root element name. To change the root element name we can use the name property of the @XmlRootElement annotation. In […]
JODA-TIME / NOTES</>↗Joda-Time25 Jul 2012
In this example you will learn how to add hours, minutes or seconds to a DateTime object in Joda-Time. Some methods are available to add or subtract hours, minutes or seconds from the object, as you can see in the example below. The DateTime object is an immutable object, which means calling one of the […]
APACHE COMMONS / NOTES</>↗Apache Commons13 Jun 2012
In this example, you will learn how to find out if two defined date objects are on the same day. It means that we are only interested in the date information and ignoring the time information of these date objects. We will be using an API provided by the Apache Commons Lang library. So here […]