diff --git a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java index 8446f3d..2f248ea 100644 --- a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java +++ b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java @@ -1,6 +1,6 @@ package com.loafle.overflow.proxy; -import com.google.common.primitives.Primitives; +import com.google.gson.internal.Primitives; import com.google.protobuf.ByteString; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; import java.lang.reflect.*; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,6 +27,23 @@ public class ServiceInvoker { private Map serviceCacheMap; + private static final Map primitiveMap; + + static { + Map primitives = new HashMap<>(8); + + primitives.put("boolean", boolean.class); + primitives.put("byte", byte.class); + primitives.put("char", char.class); + primitives.put("double", double.class); + primitives.put("float", float.class); + primitives.put("int", int.class); + primitives.put("long", long.class); + primitives.put("short", short.class); + + primitiveMap = Collections.unmodifiableMap(primitives); + } + public ServiceInvoker(ApplicationContext context) { this.context = context; objectMapper = new ObjectMapper(); @@ -97,9 +115,8 @@ public class ServiceInvoker { } } } else { - - if (Primitives.allPrimitiveTypes().contains(parameterType.getTypeName())) { - + if (Primitives.isPrimitive(parameterType)) { + parameterCache.clazz = primitiveMap.get(parameterType.getTypeName()); } else { parameterCache.clazz = Class.forName(parameterType.getTypeName()); } diff --git a/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java b/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java index 0688954..6c14e4a 100644 --- a/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java @@ -88,6 +88,9 @@ public class ServiceProxy { } catch (IllegalAccessException e) { e.printStackTrace(); responseObserver.onError(e); + } catch (InstantiationException e) { + e.printStackTrace(); + responseObserver.onError(e); }