我的 json 输入看起来像:
{ user: "sample-user", date : 1225864800 }
我的 DateDeserializer 类是:
private class DateDeserializer implements JsonDeserializer<Date>
{
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException
{
System.out.println("Deserializer...");
return new Date(json.getAsJsonPrimitive().getAsLong());
}
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Date.class, new DateDeserializer());
gson.fromJson(new FileReader("input.json"), MyType.class);
即使在设置完所有内容后,我也会得到
java.text.ParseException: Unparseable Date: "1225864800"
我在这里做错什么了吗?请帮忙。