I get this string from the server:
[
{
"title":"spoil the ones u love today",
"startDateTime":"2014-08-10T20:10:36.7158Z"
},
{
"title":"home made patisserie",
"startDateTime":"2014-08-10T20:08:45.0218Z"
}
]
and I try to parse it an object
public class Offer implements Serializable {
public String title;
public Date startDateTime;
}
Type collectionType = new TypeToken<ArrayList<Offer>>() {}.getType();
mOffersList.addAll((Collection<? extends Offer>) gson.fromJson(result, collectionType));
but when I define "startDate" as a Date
the collection I get back from gson is empty
When i define "startDate" as a String
the collection is filled correctly.
I want to change its date format. That's why I prefer saving it as a Date object.
I have tried
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").create;
and yet Gson fails to parse the server's string into
Date startDateTime
. Nothing is added to the mOffersList
and it stays empty.
What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…