Posted In: GSON, JSON

How to map multiple date formats using Gson?

Use Case – I want to map multiple date formats to Gson while converting date string to POJO Use Jackson if possible for this requirement. It has much easier to use annotations to achieve this how-to-map-multiple-date-formats-using-jackson-mapper Maven – Gson Solution – Use JsonDeserializer JsonDeserializer, gsonBuilder.registerTypeAdapter(Date.class, new DateDeserializer()) and SimpleDateFormat

Read More

Tags:

by , on December 5th, 2018

Posted In: GSON, JSON

How to map date format using Gson

Use Case – I want to map particular date format to Gson while converting date string to POJO Maven – Gson Solution GsonBuilder().setDateFormat()

Read More

Tags:

by , on December 4th, 2018

Posted In: GSON, JSON

Is Gson threadsafe?

Use Case – I want to make only one/few Gson objects and share them in various classes. Comment from Gson class Maven – Gson Test which failed in prior versions of GSON https://groups.google.com/forum/#!topic/google-gson/Vju1HuJJUIE

Read More

Tags: Tags:

by , on December 4th, 2018

Posted In: Jackson 2X, JSON

How to map multiple date formats using Jackson Mapper?

Use Case – I want to map multiple date formats to ObjectMapper while converting date string to POJO Maven – Jackson 2X Solution – Use @JsonFormat @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = “yyyy-MM-dd”, timezone = “IST”)

Read More

Tags:

by , on November 27th, 2018

Posted In: Jackson 2X, JSON

How to map date format using Jackson Mapper

Use Case – I want to map particular date format to ObjectMapper while converting date string to POJO Maven – Jackson 2X Solution ObjectMapper .. mapper.setDateFormat(SimpleDateFormat);

Read More

Tags:

by , on November 26th, 2018

Posted In: Jackson 2X, JSON

Is Jackson ObjectMapper threadsafe?

Use Case – I want to make only one/few ObjectMapper objects and share them in various classes. In this case we could use immutable ObjectReader and ObjectWriter classes Comment from ObjectWriter class Maven – Jackson 2X Solution – com.fasterxml.jackson.databind.ObjectWriter ObjectWriter objectWriter = mapper.writer(); ObjectReader objectReader = mapper.reader().forType(Employee.class);

Read More

Tags: Tags: ,

by , on November 21st, 2018

Posted In: Jackson 2X, JSON

Create custom serializer using Jackson 2.X

Use Case – While creating JSON from POJO I want to add additional logic or fields to the JSON. In the following example let us add full name which is concatenation of first name and last name. In such cases we could use Jackson custom serializer class. Maven – Jackson 2X Solution – com.fasterxml.jackson.databind.ser.std.StdSerializer Following […]

Read More

Tags:

by , on November 21st, 2018

Posted In: GSON, JSON

GSON – How to parse input JSON with dynamic keys

Use Map to parse this JSON. This will work as JSON cannot have duplicate keys.

Read More

Tags:

by , on February 23rd, 2018

Posted In: GSON, JSON

GSON – How to parse input JSON with keys as JAVA reserved keyword

Use com.google.gson.annotations.SerializedName annotation to map json key with POJO field

Read More

Tags:

by , on February 23rd, 2018

Posted In: GSON, JSON

Gson – Deserialize json array to list generic type

Converting JSON array to ArrayList<generic> can be achieved using com.google.gson.reflect.TypeToken

Read More

Tags:

by , on February 22nd, 2018