Service Invoker has been modified.

This commit is contained in:
crusader 2017-07-28 14:58:47 +09:00
parent 22adfe4688
commit c4df5dc06f
2 changed files with 13 additions and 1 deletions

View File

@ -1,8 +1,10 @@
package com.loafle.overflow.proxy; package com.loafle.overflow.proxy;
import com.google.gson.internal.Primitives;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.JavaType;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -111,7 +113,11 @@ public class ServiceInvoker {
} }
private Object getValue(Type parameterType, String json) throws IOException { 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);
} }

View File

@ -54,6 +54,12 @@ public class ServiceInvokerTest {
serviceInvoker.invoke("MemberService", "read", params3); serviceInvoker.invoke("MemberService", "read", params3);
List<ByteString> params4 = new ArrayList<>(2);
params4.add(ByteString.copyFromUtf8("ddddddfsafsd"));
params4.add(ByteString.copyFromUtf8("243234234234"));
serviceInvoker.invoke("MemberService", "signin", params4);
} }