Reputation:
I'm sending a JSON object (A rather big JSON object) to a Java servlet, I then use Gson to convert the JSON to an object. Though when I try and do so I get the following:
java.text.ParseException: Unparseable date: "May 1, 2008"
I essentially have two formats of dates in the JSON object I'm trying to parse, the second date format - the one that seems works - looks like this:
Jan 3, 1953 1:01:31 PM
The tough thing here though is that I can't edit the JSON that I'm sending through. Is there a way that I can modify the JSON server-side before trying to serialize it into an object with Gson?
Update
As requested here is my Member
JSON (I simplified it just to take into account the relative properties, as the actual JSON object I have has sensitive data and contains a lot of un-related properties):
{
"birthDate":"Jan 3, 1953 1:01:31 PM",
"beneficiaries":[
{
"terminationDate":"May 1, 2008",
"birthDate":"Jan 3, 1953",
"joinDate":"May 1, 2008"
},
{
"terminationDate":"May 1, 2008",
"birthDate":"Jan 3, 1953",
"joinDate":"May 1, 2008"
}
]
}
My POJOs:
public class Member {
private Date birthDate;
private ArrayList<Beneficiary> beneficiaries;
// Getters and Setters...
}
public class Beneficiary extends Member {
private Date terminationDate;
// Getters and Setters...
}
Upvotes: 3
Views: 1741
Reputation: 121
You can define the date format with GsonBuilder
Gson gson = new GsonBuilder().setDateFormat("your date pattern").create();
Upvotes: 5