|
5 | 5 | import com.fasterxml.jackson.databind.JavaType;
|
6 | 6 | import com.fasterxml.jackson.databind.JsonNode;
|
7 | 7 | import com.fasterxml.jackson.databind.ObjectMapper;
|
8 |
| -import com.fasterxml.jackson.databind.node.*; |
9 |
| -import com.fasterxml.jackson.databind.type.TypeFactory; |
| 8 | +import com.fasterxml.jackson.databind.node.ArrayNode; |
| 9 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 10 | +import com.fasterxml.jackson.databind.node.JsonNodeType; |
| 11 | +import com.fasterxml.jackson.databind.node.NullNode; |
| 12 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
10 | 13 | import com.googlecode.jsonrpc4j.ErrorResolver.JsonError;
|
11 | 14 | import net.iharder.Base64;
|
12 | 15 | import org.slf4j.Logger;
|
|
17 | 20 | import java.io.InputStream;
|
18 | 21 | import java.io.OutputStream;
|
19 | 22 | import java.lang.annotation.Annotation;
|
20 |
| -import java.lang.reflect.*; |
| 23 | + |
| 24 | +import java.lang.reflect.InvocationTargetException; |
| 25 | +import java.lang.reflect.Method; |
| 26 | +import java.lang.reflect.Proxy; |
| 27 | +import java.lang.reflect.Type; |
| 28 | +import java.lang.reflect.UndeclaredThrowableException; |
21 | 29 | import java.math.BigDecimal;
|
22 | 30 | import java.nio.charset.StandardCharsets;
|
23 |
| -import java.util.*; |
24 |
| -import java.util.logging.Level; |
| 31 | + |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.Collection; |
| 34 | +import java.util.HashSet; |
| 35 | +import java.util.Iterator; |
| 36 | +import java.util.List; |
| 37 | +import java.util.Map; |
| 38 | +import java.util.Set; |
25 | 39 | import java.util.regex.Pattern;
|
26 | 40 |
|
27 | 41 | import static com.googlecode.jsonrpc4j.ErrorResolver.JsonError.ERROR_NOT_HANDLED;
|
@@ -610,33 +624,7 @@ private AMethodWithItsArgs findBestMethodByParamsNode(Set<Method> methods, JsonN
|
610 | 624 | throw new IllegalArgumentException("Unknown params node type: " + paramsNode.toString());
|
611 | 625 | }
|
612 | 626 | if(matchedMethod==null) {
|
613 |
| - for (Method method : methods) { |
614 |
| - if(method.getParameterTypes().length!=1) { |
615 |
| - continue; |
616 |
| - } |
617 |
| - if(method.isVarArgs()) { |
618 |
| - matchedMethod = new AMethodWithItsArgs(method); |
619 |
| - |
620 |
| - if (paramsNode.isArray()) { |
621 |
| - ArrayNode arrayNode = ArrayNode.class.cast(paramsNode); |
622 |
| - for (int i = 0; i < paramsNode.size(); i++) { |
623 |
| - matchedMethod.arguments.add(arrayNode.get(i)); |
624 |
| - } |
625 |
| - } |
626 |
| - |
627 |
| - if (paramsNode.isObject()) { |
628 |
| - ObjectNode objectNode = ObjectNode.class.cast(paramsNode); |
629 |
| - Iterator<Map.Entry<String, JsonNode>> items = objectNode.fields(); |
630 |
| - while (items.hasNext()) { |
631 |
| - Map.Entry<String, JsonNode> item = items.next(); |
632 |
| - JsonNode name = JsonNodeFactory.instance.objectNode().put(item.getKey(),item.getKey()); |
633 |
| - matchedMethod.arguments.add(name.get(item.getKey())); |
634 |
| - matchedMethod.arguments.add(item.getValue()); |
635 |
| - } |
636 |
| - } |
637 |
| - break; |
638 |
| - } |
639 |
| - } |
| 627 | + matchedMethod = findBestMethodForVarargs(methods, paramsNode); |
640 | 628 | }
|
641 | 629 | return matchedMethod;
|
642 | 630 | }
|
@@ -687,6 +675,37 @@ private Method getBestMatchingArgTypeMethod(ArrayNode paramNodes, int numParams,
|
687 | 675 | }
|
688 | 676 | return bestMethod;
|
689 | 677 | }
|
| 678 | + |
| 679 | + private AMethodWithItsArgs findBestMethodForVarargs(Set<Method> methods, JsonNode paramsNode) { |
| 680 | + for (Method method : methods) { |
| 681 | + if(method.getParameterTypes().length!=1) { |
| 682 | + continue; |
| 683 | + } |
| 684 | + if(method.isVarArgs()) { |
| 685 | + AMethodWithItsArgs matchedMethod = new AMethodWithItsArgs(method); |
| 686 | + |
| 687 | + if (paramsNode.isArray()) { |
| 688 | + ArrayNode arrayNode = ArrayNode.class.cast(paramsNode); |
| 689 | + for (int i = 0; i < paramsNode.size(); i++) { |
| 690 | + matchedMethod.arguments.add(arrayNode.get(i)); |
| 691 | + } |
| 692 | + } |
| 693 | + |
| 694 | + if (paramsNode.isObject()) { |
| 695 | + ObjectNode objectNode = ObjectNode.class.cast(paramsNode); |
| 696 | + Iterator<Map.Entry<String, JsonNode>> items = objectNode.fields(); |
| 697 | + while (items.hasNext()) { |
| 698 | + Map.Entry<String, JsonNode> item = items.next(); |
| 699 | + JsonNode name = JsonNodeFactory.instance.objectNode().put(item.getKey(),item.getKey()); |
| 700 | + matchedMethod.arguments.add(name.get(item.getKey())); |
| 701 | + matchedMethod.arguments.add(item.getValue()); |
| 702 | + } |
| 703 | + } |
| 704 | + return matchedMethod; |
| 705 | + } |
| 706 | + } |
| 707 | + return null; |
| 708 | + } |
690 | 709 |
|
691 | 710 | private int getNumArgTypeMatches(ArrayNode paramNodes, int numParams, List<Class<?>> parameterTypes) {
|
692 | 711 | int numMatches = 0;
|
|
0 commit comments