From 4ee1df372b33fca7ab7d4d52f604a17cce01296c Mon Sep 17 00:00:00 2001 From: snoop Date: Thu, 26 Apr 2018 14:13:31 +0900 Subject: [PATCH] fixed gson -> jackson --- .../commons/utils/JsonDateDeserializer.java | 21 ------------------- .../service/TargetDiscoveryServiceTest.java | 14 ++++++------- 2 files changed, 6 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/central/commons/utils/JsonDateDeserializer.java diff --git a/src/main/java/com/loafle/overflow/central/commons/utils/JsonDateDeserializer.java b/src/main/java/com/loafle/overflow/central/commons/utils/JsonDateDeserializer.java deleted file mode 100644 index 72e0b0e..0000000 --- a/src/main/java/com/loafle/overflow/central/commons/utils/JsonDateDeserializer.java +++ /dev/null @@ -1,21 +0,0 @@ -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 { - 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; - } -} diff --git a/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java b/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java index b2e6a26..1724465 100644 --- a/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/target/service/TargetDiscoveryServiceTest.java @@ -4,12 +4,13 @@ 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; import com.loafle.overflow.model.probe.Probe; import com.loafle.overflow.service.central.target.TargetDiscoveryService; + import org.codehaus.jackson.map.DeserializationConfig; + import org.codehaus.jackson.map.ObjectMapper; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,18 +49,15 @@ String json = readFileAsString(resourceLoader.getResource("classpath:2018-04-25-tds.json").getURI().getPath()); - Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create(); +// Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDateDeserializer()).create(); -// ObjectMapper mapper = new ObjectMapper(); -// -// mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ObjectMapper mapper = new ObjectMapper(); -// List hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class)); + mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Type listType = new TypeToken>(){}.getType(); + List hosts = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Host.class)); - List hosts = gson.fromJson(json, listType); Probe probe = new Probe(); probe.setId(1);