From c4df5dc06fcbc0d34ad398e7389d1aaf45a5cdde Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 28 Jul 2017 14:58:47 +0900 Subject: [PATCH] Service Invoker has been modified. --- .../java/com/loafle/overflow/proxy/ServiceInvoker.java | 8 +++++++- .../com/loafle/overflow/proxy/ServiceInvokerTest.java | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java index 78afd81..ce2b3da 100644 --- a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java +++ b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java @@ -1,8 +1,10 @@ package com.loafle.overflow.proxy; +import com.google.gson.internal.Primitives; import com.google.protobuf.ByteString; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.JavaType; import org.springframework.aop.support.AopUtils; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; @@ -111,7 +113,11 @@ public class ServiceInvoker { } private Object getValue(Type parameterType, String json) throws IOException { - return objectMapper.readValue(json, objectMapper.getTypeFactory().constructType(parameterType)); + JavaType targetType = objectMapper.getTypeFactory().constructType(parameterType); + if (!Primitives.isPrimitive(parameterType) && !parameterType.getTypeName().equals(String.class.getName())) { + return objectMapper.readValue(json, targetType); + } + return objectMapper.convertValue(json, targetType); } diff --git a/src/test/java/com/loafle/overflow/proxy/ServiceInvokerTest.java b/src/test/java/com/loafle/overflow/proxy/ServiceInvokerTest.java index c48aee4..2ac2a54 100644 --- a/src/test/java/com/loafle/overflow/proxy/ServiceInvokerTest.java +++ b/src/test/java/com/loafle/overflow/proxy/ServiceInvokerTest.java @@ -54,6 +54,12 @@ public class ServiceInvokerTest { serviceInvoker.invoke("MemberService", "read", params3); + List params4 = new ArrayList<>(2); + params4.add(ByteString.copyFromUtf8("ddddddfsafsd")); + params4.add(ByteString.copyFromUtf8("243234234234")); + + serviceInvoker.invoke("MemberService", "signin", params4); + }