Spring bean reflection
This commit is contained in:
parent
b3d1fff6b5
commit
e3d3a94ab7
|
@ -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<String, Cache> serviceCacheMap;
|
||||
|
||||
private static final Map<String, Class> primitiveMap;
|
||||
|
||||
static {
|
||||
Map<String, Class> 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());
|
||||
}
|
||||
|
|
|
@ -88,6 +88,9 @@ public class ServiceProxy {
|
|||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
responseObserver.onError(e);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
responseObserver.onError(e);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user