|
21 | 21 |
|
22 | 22 | import com.vaadin.flow.component.ClientCallable; |
23 | 23 | import com.vaadin.flow.component.Component; |
24 | | -import elemental.json.JsonArray; |
25 | | -import elemental.json.JsonBoolean; |
26 | | -import elemental.json.JsonNumber; |
27 | | -import elemental.json.JsonObject; |
28 | | -import elemental.json.JsonString; |
29 | 24 | import elemental.json.JsonValue; |
| 25 | +import java.lang.invoke.MethodHandle; |
| 26 | +import java.lang.invoke.MethodHandles; |
| 27 | +import java.lang.invoke.MethodType; |
30 | 28 | import java.lang.reflect.Constructor; |
31 | 29 | import java.lang.reflect.Method; |
32 | 30 | import java.lang.reflect.Modifier; |
|
36 | 34 | import java.util.concurrent.ConcurrentHashMap; |
37 | 35 | import java.util.stream.Collectors; |
38 | 36 | import java.util.stream.Stream; |
| 37 | +import lombok.SneakyThrows; |
39 | 38 | import org.objectweb.asm.ClassWriter; |
40 | 39 | import org.objectweb.asm.MethodVisitor; |
41 | 40 | import org.objectweb.asm.Opcodes; |
42 | 41 | import org.objectweb.asm.Type; |
43 | | -import tools.jackson.databind.JsonNode; |
44 | | -import tools.jackson.databind.node.ArrayNode; |
45 | | -import tools.jackson.databind.node.BooleanNode; |
46 | | -import tools.jackson.databind.node.DoubleNode; |
47 | | -import tools.jackson.databind.node.ObjectNode; |
48 | | -import tools.jackson.databind.node.StringNode; |
49 | 42 |
|
50 | 43 | /** |
51 | 44 | * Utility class for instrumenting classes at runtime. |
@@ -377,21 +370,17 @@ private String getMethodDescriptor(Method method, boolean convertJsonValueParams |
377 | 370 | return sb.toString(); |
378 | 371 | } |
379 | 372 |
|
| 373 | + private MethodHandle getConvertedTypeDescriptor; |
| 374 | + |
| 375 | + @SneakyThrows |
380 | 376 | private String getConvertedTypeDescriptor(Class<?> type) { |
381 | | - if (type == JsonObject.class) { |
382 | | - return Type.getDescriptor(ObjectNode.class); |
383 | | - } else if (type == JsonArray.class) { |
384 | | - return Type.getDescriptor(ArrayNode.class); |
385 | | - } else if (type == JsonBoolean.class) { |
386 | | - return Type.getDescriptor(BooleanNode.class); |
387 | | - } else if (type == JsonNumber.class) { |
388 | | - return Type.getDescriptor(DoubleNode.class); |
389 | | - } else if (type == JsonString.class) { |
390 | | - return Type.getDescriptor(StringNode.class); |
391 | | - } else if (JsonValue.class.isAssignableFrom(type)) { |
392 | | - return Type.getDescriptor(JsonNode.class); |
| 377 | + if (getConvertedTypeDescriptor == null) { |
| 378 | + Class<?> helper = Class.forName("com.flowingcode.vaadin.jsonmigration.ClassInstrumentationJacksonHelper"); |
| 379 | + MethodHandles.Lookup lookup = MethodHandles.lookup(); |
| 380 | + MethodType methodType = MethodType.methodType(String.class, Class.class); |
| 381 | + getConvertedTypeDescriptor = lookup.findStatic(helper, "getConvertedTypeDescriptor", methodType); |
393 | 382 | } |
394 | | - return Type.getDescriptor(type); |
| 383 | + return (String) getConvertedTypeDescriptor.invokeExact(type); |
395 | 384 | } |
396 | 385 |
|
397 | 386 | private String[] getExceptionInternalNames(Class<?>[] exceptionTypes) { |
|
0 commit comments