From 8be75eb5440a4cde80892599e51a0635732a5efb Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Fri, 23 Aug 2024 16:19:31 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=ED=86=A1/?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=20=EB=AA=A8=EB=B0=94=EC=9D=BC=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=ED=98=B8=EC=B6=9C=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/mbl/service/MobilePageService.java | 11 ++- .../xit/core/spring/util/MapDeserailizer.java | 67 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 mens-api/src/main/java/kr/xit/core/spring/util/MapDeserailizer.java diff --git a/mens-api/src/main/java/kr/xit/biz/mbl/service/MobilePageService.java b/mens-api/src/main/java/kr/xit/biz/mbl/service/MobilePageService.java index 9393b9a..69ce6f0 100644 --- a/mens-api/src/main/java/kr/xit/biz/mbl/service/MobilePageService.java +++ b/mens-api/src/main/java/kr/xit/biz/mbl/service/MobilePageService.java @@ -1,10 +1,14 @@ package kr.xit.biz.mbl.service; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.stereotype.Service; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import kr.xit.biz.ens.model.cntc.CntcDTO; import kr.xit.biz.ens.model.kakao.v1.KkopayDocDTO; import kr.xit.biz.ens.model.kt.KtCommonDTO; @@ -18,6 +22,7 @@ import kr.xit.core.model.ApiResponseDTO; import kr.xit.core.model.IApiResponse; import kr.xit.core.service.AbstractService; import kr.xit.core.spring.annotation.TraceLogging; +import kr.xit.core.spring.util.MapDeserailizer; import kr.xit.core.support.utils.Checks; import kr.xit.core.support.utils.JsonUtils; import kr.xit.ens.kakao.v1.service.IKkopayEltrcDocService; @@ -50,6 +55,7 @@ public class MobilePageService extends AbstractService implements IMobilePageSer private final IKkotalkEltrcDocService kkotalkService; private final IKtBcService ktMmsService; + private Gson gson = new GsonBuilder().registerTypeAdapter(Map.class, new MapDeserailizer()).serializeNulls().create(); /** *
      * 카카오 내문서함 모바일 페이지 컨탠트 요청
@@ -127,7 +133,10 @@ public class MobilePageService extends AbstractService implements IMobilePageSer
         // if(!res.isSuccess()){
         //     throw BizRuntimeException.create(res.getMessage());
         // }
-        return JsonUtils.toObject(mobilePageManage.getMobilePageCn(), Map.class);
+        Map>> map = gson.fromJson(mobilePageManage.getMobilePageCn(), Map.class);
+        Map>> mobilePage = new HashMap<>();
+        mobilePage.put("details", map.get("details"));
+        return mobilePage;
     }
 
     /**
diff --git a/mens-api/src/main/java/kr/xit/core/spring/util/MapDeserailizer.java b/mens-api/src/main/java/kr/xit/core/spring/util/MapDeserailizer.java
new file mode 100644
index 0000000..4f4a881
--- /dev/null
+++ b/mens-api/src/main/java/kr/xit/core/spring/util/MapDeserailizer.java
@@ -0,0 +1,67 @@
+package kr.xit.core.spring.util;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonDeserializationContext;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParseException;
+import com.google.gson.JsonPrimitive;
+
+public class MapDeserailizer implements JsonDeserializer> {
+
+    @Override @SuppressWarnings("unchecked")
+    public Map deserialize(JsonElement json, Type typeOfT,
+                                           JsonDeserializationContext context) throws JsonParseException {
+        return (Map) read(json);
+    }
+
+    public Object read(JsonElement in) {
+        if(in.isJsonArray()){
+
+            List list = new ArrayList();
+            JsonArray arr = in.getAsJsonArray();
+            for (JsonElement anArr : arr) {
+
+                list.add(read(anArr));
+            }
+            return list;
+        }else if(in.isJsonObject()){
+            Map map = new HashMap();
+            JsonObject obj = in.getAsJsonObject();
+            Set> entitySet = obj.entrySet();
+            for(Map.Entry entry: entitySet){
+
+                map.put(entry.getKey(), read(entry.getValue()));
+            }
+            return map;
+        }else if( in.isJsonPrimitive()){
+            JsonPrimitive prim = in.getAsJsonPrimitive();
+            if(prim.isBoolean()){
+
+                return prim.getAsBoolean();
+            }else if(prim.isString()){
+
+                return prim.getAsString();
+            }else if(prim.isNumber()){
+                Number num = prim.getAsNumber();
+
+                if(Math.ceil(num.doubleValue()) == num.longValue())
+
+                    return num.longValue();
+                else{
+
+                    return num.doubleValue();
+                }
+            }
+        }
+        return null;
+    }
+}