Gson Date 适配器

JsonDeserializer<Date> deser = new JsonDeserializer<Date>() {
            @Override
            public Date deserialize(JsonElement json, Type typeOfT,
                                    JsonDeserializationContext context) throws JsonParseException {
                return json == null ? null : new Date(json.getAsLong());
            }
        };

        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, deser).create();
        return gson.fromJson(json , YOUROBJECT.class);

 

posted on 2020-03-20 15:09  SkyBall  阅读(325)  评论(0编辑  收藏  举报