Previous data-binding posts gave the idea about how the POJO’s are mapped to JSON and viceversa using ObjectMapper API. This post will demonstrate same POJO to JSON Data-binding example using commonly used Jackson JSON Annotations. Basic operations read/write will be implemented exactly as before, but POJO’s are annotated this time. Let’s get going. We will…
Continue readingJava
Jackson Streaming Api Example
For situations where performance is most critical, Jackson comes with Streaming API which is a high performance, sequential access api, with very low memory footprints and processing overhead. Due to it’s incremental processing/sequential access nature, all content must be read/write in order as it arrives, so it’s bit hard to use. This API is mainly…
Continue readingJackson Tree Model Example
Conceptually JSON can be represented as a Tree (similar to DOM tree). Therefore it is possible to traverse to individual nodes in the tree in order to access/edit their values. Jackson library provides api to do it. JsonNode refers to an individual node in tree which can be accessed using node name.ObjectMappers readTree and writeTree…
Continue readingConverting JSON to/from Java Maps using JACKSON API
Since JSON format is essentially a key-value pair grouping, JSON can easily be converted to/from Java maps. This post is about JSON to MAP conversion. Let’s get going. Step 1: Include JACKSON dependency in pom.xml There are several jar in JACKSON library. For this example, we are only using databind. Step 2: Convert Java Map…
Continue readingConverting JSON to/from Java Objects using JACKSON API
This post explains Jackson data-binding, which is a common approach when dealing with JSON using Jackson API in your Java projects. Let’s get going. ObjectMapper is the main api used for data-binding. It comes with several reader/writer methods to preform the conversion from/to Java and JSON Typical usages are as follows: Complete Example Step 1:…
Continue readingJson Structure
Java Script Object Notation (JSON) is one of the most popular and commonly used way to represent information. This post explains simple & complex constructions of JSON message structures. Let’s take an example of a Car. Information about a Car can be represented in Json format as follows: Above representation is derived from Javascript. Here…
Continue readingJAXB2 Annotations
This post explains some of the frequently used JAXB2 annotations. For the complete list of JAXB2 annotations, please visit API Page. Let’s quickly have a look of the mapped class, and the XML it will generate, then we will go through annotations, one at a time. Mapped Class Adapter class used in Mapped Class Generated…
Continue readingJAXB2 Code Generation Maven Example
This post demonstrates JAXB2 Code generation example using maven-jaxb2-plugin, adding generated code to source with build-helper-maven-plugin. Sometimes, while integrating with third party software, we only get XSD’s as input. In such situations, we are responsible to generate the actual JAXB2 compliant Java code which can then be used on client side to perform integration with…
Continue readingJAXB2 Schema Validation Example
This post shown how JAXB2 Schema validation can be used in your project, validating the generated XML against specific XML Schema Definition [XSD]. An XML Schema Definition describes the structure of an XML document and governs the rules and constraints being applied on XML content. JAXB2 provides API to validate the generated XML against an…
Continue readingJAXB2 Helloworld Example,Marshal/UnMarshal Example
This JAXB2 Helloworld example post explains the basics of JAXB along with core concepts like Mapping, Marshalling & Unmarshalling XML to Java objects and vice versa, commonly used JAXB annotations, JAXBContext setup and API usage, XmlAdapter usage etc. Let’s go through them one by one: 1) Mapping Mapping refers to binding Java objects to XML…
Continue reading