【問題】Gson格式化報錯
java.text.ParseException: Failed to parse date ["1525688551000']: Invalid time zone indicator '5'
【修復】用GsonBuilder 註冊Date類型
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return new Date(json.getAsJsonPrimitive().getAsLong());
}
});
Gson gson = builder.create();
【是否我導致】是【解決Bug的時間】10分鐘
【教訓】注意時間格式的json轉換