Skip to content
This repository has been archived by the owner on Jan 2, 2022. It is now read-only.

Fixed bug - false detection of circular reference #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added support for Gson configuration. (useful for Date format)
  • Loading branch information
parvanov committed Aug 15, 2013
commit 78f1c45e508259de0462210bf80ed50253dd807b
16 changes: 12 additions & 4 deletions jsonrpc-java/src/main/java/org/json/rpc/client/JsonRpcInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,30 @@ public final class JsonRpcInvoker {

private final TypeChecker typeChecker;

private final Gson gson;

public JsonRpcInvoker() {
this(new GsonTypeChecker());
this(new GsonTypeChecker(), new Gson());
}

public JsonRpcInvoker(Gson gson) {
this(new GsonTypeChecker(), gson);
}

public JsonRpcInvoker(TypeChecker typeChecker) {
this(typeChecker, new Gson());
}

public JsonRpcInvoker(TypeChecker typeChecker, Gson gson) {
this.typeChecker = typeChecker;
this.gson = gson;
}

public <T> T get(final JsonRpcClientTransport transport, final String handle, final Class<T>... classes) {
for (Class<T> clazz : classes) {
typeChecker.isValidInterface(clazz);
}
return (T) Proxy.newProxyInstance(JsonRpcInvoker.class.getClassLoader(), classes, new InvocationHandler() {

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return JsonRpcInvoker.this.invoke(handle, transport, method, args);
}
Expand All @@ -68,8 +78,6 @@ private Object invoke(String handleName,
int id = rand.nextInt(Integer.MAX_VALUE);
String methodName = handleName + "." + method.getName();

Gson gson = new Gson();

JsonObject req = new JsonObject();
req.addProperty("id", id);
req.addProperty("method", methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@ public final class JsonRpcExecutor implements RpcIntroSpection {

private final TypeChecker typeChecker;
private volatile boolean locked;

private final Gson gson;

public JsonRpcExecutor() {
this(new GsonTypeChecker());
this(new GsonTypeChecker(), new Gson());
}

public JsonRpcExecutor(Gson gson) {
this(new GsonTypeChecker(), gson);
}

@SuppressWarnings("unchecked")
public JsonRpcExecutor(TypeChecker typeChecker) {
this(typeChecker, new Gson());
}

@SuppressWarnings("unchecked")
public JsonRpcExecutor(TypeChecker typeChecker, Gson gson) {
this.typeChecker = typeChecker;
this.gson = gson;
this.handlers = new HashMap<String, HandleEntry<?>>();
addHandler("system", this, RpcIntroSpection.class);
}
Expand Down Expand Up @@ -239,7 +250,7 @@ private JsonElement executeMethod(String methodName, JsonArray params) throws Th
Object result = executableMethod.invoke(
handleEntry.getHandler(), getParameters(executableMethod, params));

return new Gson().toJsonTree(result);
return gson.toJsonTree(result);
} catch (Throwable t) {
if (t instanceof InvocationTargetException) {
t = ((InvocationTargetException) t).getTargetException();
Expand All @@ -261,7 +272,6 @@ public boolean canExecute(Method method, JsonArray params) {

public Object[] getParameters(Method method, JsonArray params) {
List<Object> list = new ArrayList<Object>();
Gson gson = new Gson();
Class<?>[] types = method.getParameterTypes();
for (int i = 0; i < types.length; i++) {
JsonElement p = params.get(i);
Expand Down