Using Custom DateFormat

In this post, under JSONB, I will explain how to use custom date format when serializing/deserializing Java object containing date information to json format. By default JSONB when converting date information to json it prints in the format as shown below 2019-02-16T07:16:38.537Z[UTC] We can change this format globally, globally meaning the custom format will be…… Continue reading Using Custom DateFormat

Custom format for Property names using PropertyNamingStrategy Part 2

In this post under JSONB, I will continue explaining how to create custom format for property names using PropertyNamingStrategy interface. In the post, “Custom format for Property names using PropertyNamingStrategy Part 1”, I listed the different formats provided by the interface out of the box, which are 1) CASE_INSENSITIVE 2) IDENTITY 3) LOWER_CASE_WITH_DASHES 4) LOWER_CASE_WITH_UNDERSCORES…… Continue reading Custom format for Property names using PropertyNamingStrategy Part 2

Custom format for Property names using PropertyNamingStrategy Part 1

In this post under JSONB, I will explain how to create custom format for property names using PropertyNamingStrategy interface. Whenever we serialize a java object to JSON format, the property or field names in json are same as property names in its corresponding java class. For example when we serialize the below java class instance…… Continue reading Custom format for Property names using PropertyNamingStrategy Part 1

Configuring the Jsonb instance

From the previous posts we can see that an instance of Jsonb is used for serialization/deserialization of java objects to/from json format. We can configure the Jsonb instance by creating an instance of JsonbConfig. By default jsonb implementation provider must support the following properties to be configured. jsonb.to.json.formatted – java.lang.Boolean Controls whether or not the…… Continue reading Configuring the Jsonb instance

Serialization of null values when converting from java object to json format

In this post I will explain how serialization of null values feature can be turned on or off. Below is the class structure of the object to be serialized Student 1 import javax.json.bind.annotation.JsonbProperty; 2 3 public class Student { 4 private int id; 5 private String name; 6 private Integer rollnum; 7 8 public int…… Continue reading Serialization of null values when converting from java object to json format

Preventing an property from being serialized to json

By default when an object is serialized to json format, all the properties in the object are serialized. We cannot prevent this default behavior, by annotating the property with @JsonbTransient annotation. Below is the example. The class to be serialized is Employee Employee 1 import javax.json.bind.annotation.JsonbTransient; 2 3 public class Employee { 4 private int…… Continue reading Preventing an property from being serialized to json