Marshalling and Unmarshalling a generic object

In this post under Jackson –> JSON, I will explain with example how to marshal and unmarshal a generic object. Below is the complete main code for your reference Main class 1 package package14; 2 3 import com.fasterxml.jackson.core.type.TypeReference; 4 import com.fasterxml.jackson.databind.ObjectMapper; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class Example14 { 10…… Continue reading Marshalling and Unmarshalling a generic object

Checking whether yaml parser feature is enabled or not

In this post under Jackson YAML, I will show with example how to check whether a yaml parser feature is enabled or not. In previous post under Jackson YAML, I explained the purpose of yaml parser feature “YAMLParser.Feature.PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS”. For our example I will check whether the above parser feature is enabled or not. Below is…… Continue reading Checking whether yaml parser feature is enabled or not

Yaml parser feature PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS

In this post under Jackson Yaml, I will explain the purpose of parser feature “PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS” and how to enable or disable it. We all know that YAML parser, when parsing a file, if it encounters word “true” or “false” it treats them as boolean. In addition to that, synonyms of “true” and “false” like “yes”…… Continue reading Yaml parser feature PARSE_BOOLEAN_LIKE_WORDS_AS_STRINGS

UnMarshalling YAML file to Java Object

This post explains unmarshalling information stored in YAML format to java object . This can be achieved with the help of YAMLMapper provided by jackson package. To explain with an example we will use the below pojo objects Employee package package2; import java.math.BigDecimal; import java.util.List; public class Employee { private String id; private String name;…… Continue reading UnMarshalling YAML file to Java Object

Marshalling Java Object to YAML format

This post explains marshalling a java object to YAML format and storing it to a file. This can be achieved with the help of YAMLMapper provided by jackson package. To explain with an example we will use the below pojo objects. Employee package package2; import java.math.BigDecimal; import java.util.List; public class Employee { private String id;…… Continue reading Marshalling Java Object to YAML format

Creating a YAML file

The below post explains how to write YAML data to file using YAMLGenerator. YAMLGenerator writes the data to a file in streaming way, helping the developer using the api to avoid creating an object representation of the entire data. We can get an instance of YAMLGenerator with the help of an instance of YAMLFactory as…… Continue reading Creating a YAML file

Parsing a YAML file

In this post I will explain how to parse a YAML file using Jackson framework. We need the following jars in our classpath 1) jackson-dataformat-yaml-2.9.6.jar 2) snakeyaml-1.18.jar 3) jackson-annotations-2.9.0.jar 4) jackson-core-2.9.6.jar 5) jackson-databind-2.9.6.jar First we need to create an instance of YAMLFactory class. It is factory class used to create instance of YAMLParser (reader) and…… Continue reading Parsing a YAML file

Achieving data binding with object model

This post explains how to achieve mapping of json data represented by an object model to particular java object. Here object model is tree like data structure which reads and stores the entire json content in memory. The difference between this post and other posts in Binding section is that latter posts explains marshalling and…… Continue reading Achieving data binding with object model

Creating and Writing JSON object model to a file

This post explains how to create and save json object model to a file. In the example we build the below json object model representing person information. { “ssn” : “111111111”, “name” : { “firstName” : “Ronald”, “lastName” : “Childs” }, “phoneNumbers” : [ “1112223333”, “4445556666” ] } The main code is as shown below…… Continue reading Creating and Writing JSON object model to a file

Printing json data in a formatted way

This post explains how to print json data in a properly formatted way, whether the destination is console, file etc. For example when the below code prints the json data to a file, the output will be as shown below Initial Code package package11; import java.io.File; import java.io.FileWriter; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; public…… Continue reading Printing json data in a formatted way