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: 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

Posted In: GSON, JSON

GSON – How to exclude fields during serialization/toJSON using JsonSerializer

Use com.google.gson.JsonSerializer to add only required fields Output maiingAddress is excluded

Read More

Tags: Tags:

by , on February 22nd, 2018

Posted In: GSON, JSON

GSON – How to exclude fields during serialization/toJSON

Use com.google.gson.annotations.Expose to exclude Output maiingAddress is excluded

Read More

Tags:

by , on February 22nd, 2018

Posted In: GSON, JSON

GSON – Resolving Expected BEGIN_OBJECT but was BEGIN_ARRAY exception

Code will throw following error com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 13 path $.student at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224) To resolve either POJO or input JSON needs to be corrected

Read More

Tags:

by , on February 22nd, 2018

Posted In: GSON, JSON

GSON TypeAdapter – How to process large JSON file

I have successfully tried this code with 90K records. This is useful in following scenarios When it is impossible or undesirable to load the entire object model into memory. This is most relevant on mobile platforms where memory is limited. When it is necessary to read or write a document before it is completely available. […]

Read More

Tags: Tags:

by , on February 21st, 2018