fixed gson date

This commit is contained in:
snoop 2018-04-25 21:45:11 +09:00
parent 752be72906
commit b8971008be
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package com.loafle.overflow.central.commons.utils;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.util.Date;
/**
* Created by snoop on 18. 4. 25.
*/
public class JsonDateDeserializer implements JsonDeserializer<Date> {
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String s = json.getAsJsonPrimitive().getAsString();
long l = Long.parseLong(s.substring(6, s.length() - 2));
Date d = new Date(l);
return d;
}
}

View File

@ -2,7 +2,9 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.loafle.overflow.central.commons.utils.JsonDateDeserializer;
import com.loafle.overflow.central.spring.AppConfigTest;
import com.loafle.overflow.model.discovery.Host;
@ -23,6 +25,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
/**
@ -45,7 +48,8 @@
String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath());
Gson gson = new Gson();
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create();
// ObjectMapper mapper = new ObjectMapper();
//