I’m using Gson to convert Json to an object in Java. Json that i’m trying to convert has quite complicated structure.
{
"name": "0",
"dtExpiration": "07/14/2011 00:00",
"quotaList": null,
"question_array": [
{
"question": "0",
"questionType": "resposta de texto",
"min": "null",
"max": "null",
"responceList": [],
"answer_array": [
{
...
1.The question is: will gson.fromJson(json, SuperClass.class) work, as this class has ArrayLists?
I can’t see if it works, because I have a problem with date format. The program throws exception:
Caused by: java.text.ParseException: Unparseable date: "07/15/2011 00:00"
So I had tried to specify format by using:
GsonBuilder gson = new GsonBuilder().setDateFormat("mm/dd/yyyy hh:mm");
but result is the same.
2.Can you explain me how to change date format using GsonBuilder?
Thank you
Yes, provided the
SuperClassstructure matches the JSON structure.Use big “M” for month in year. Small “m” is for minute in hour.
Here’s a working example.
Note that on my system, it changed from the 24H clock display to the 12H clock display.