Take a look at Gson docs
Gson gson = new Gson();
int[] ints = {1, 2, 3, 4, 5};
String[] strings = {"abc", "def", "ghi"};
(Serialization)
gson.toJson(ints); ==> prints [1,2,3,4,5]
gson.toJson(strings); ==> prints ["abc", "def", "ghi"]
(Deserialization)
int[] ints2 = gson.fromJson("[1,2,3,4,5]", int[].class);
==> ints2 will be same as ints
Tis is important for you: We also support multi-dimensional arrays, with arbitrarily complex element types
For null
objects, Gson
by default will not convert as null. Ref.
But you can configure to scan those nulls
attributes if you want to do it after.
The default behaviour that is implemented in Gson
is that null object fields are ignored. This allows for a more compact output format; however, the client must define a default value for these fields as the JSON
format is converted back into its Java.
Here's how you would configure a Gson
instance to output null:
Gson gson = new GsonBuilder().serializeNulls().create();
In your problem maybe you don't need to configure that.
I hope it helps.