diff --git a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationJacksonHelper.java b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationJacksonHelper.java index 6cb90c4..7e29c32 100644 --- a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationJacksonHelper.java +++ b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationJacksonHelper.java @@ -48,6 +48,8 @@ public static String getConvertedTypeDescriptor(Class type) { return Type.getDescriptor(StringNode.class); } else if (JsonValue.class.isAssignableFrom(type)) { return Type.getDescriptor(JsonNode.class); + } else if (JsonValue[].class.isAssignableFrom(type)) { + return "[" + getConvertedTypeDescriptor(type.getComponentType()); } return Type.getDescriptor(type); } diff --git a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java index ce6eb38..d089878 100644 --- a/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java +++ b/src/main/java/com/flowingcode/vaadin/jsonmigration/ClassInstrumentationUtil.java @@ -237,7 +237,8 @@ private List getInstrumentableMethods(Class parent) { private static boolean hasJsonValueParameters(Method method) { for (Class paramType : method.getParameterTypes()) { - if (JsonValue.class.isAssignableFrom(paramType)) { + if (JsonValue.class.isAssignableFrom(paramType) + || JsonValue[].class.isAssignableFrom(paramType)) { return true; } } @@ -582,7 +583,7 @@ private int loadParameter(MethodVisitor mv, Class paramType, int localVarInde private String getMethodDescriptor(Method method, boolean convertJsonValueParams) { StringBuilder sb = new StringBuilder("("); for (Class paramType : method.getParameterTypes()) { - if (convertJsonValueParams && JsonValue.class.isAssignableFrom(paramType)) { + if (convertJsonValueParams) { sb.append(getConvertedTypeDescriptor(paramType)); } else { sb.append(Type.getDescriptor(paramType)); diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_ArrayOfJsonObject__V.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_ArrayOfJsonObject__V.java new file mode 100644 index 0000000..6615966 --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_ArrayOfJsonObject__V.java @@ -0,0 +1,36 @@ +/*- + * #%L + * Json Migration Helper + * %% + * Copyright (C) 2025 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.flowingcode.vaadin.jsonmigration; + +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.not; +import com.vaadin.flow.component.ClientCallable; +import elemental.json.JsonObject; +import org.junit.Assert; + +public class ClientCallable_ArrayOfJsonObject__V extends BaseClientCallable { + + @ClientCallable + public void test(JsonObject[] arg) { + Assert.assertNotNull(arg); + Assert.assertThat(arg, not(emptyArray())); + trace(); + } +} diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_JsonObjectVarargs__V.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_JsonObjectVarargs__V.java new file mode 100644 index 0000000..2a23c5a --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallable_JsonObjectVarargs__V.java @@ -0,0 +1,36 @@ +/*- + * #%L + * Json Migration Helper + * %% + * Copyright (C) 2025 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.flowingcode.vaadin.jsonmigration; + +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.not; +import com.vaadin.flow.component.ClientCallable; +import elemental.json.JsonObject; +import org.junit.Assert; + +public class ClientCallable_JsonObjectVarargs__V extends BaseClientCallable { + + @ClientCallable + public void test(JsonObject[] arg) { + Assert.assertNotNull(arg); + Assert.assertThat(arg, not(emptyArray())); + trace(); + } +} diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest.java index db1884d..5a7757c 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest.java @@ -77,6 +77,8 @@ private Object invokeTestMethod(BaseClientCallable instrumented, Object... args) protected abstract Object createJsonObject(); + protected abstract Object createArrayOfJsonObject(); + @Test public void test__V() throws Exception { ClientCallable__V instrumented = @@ -282,4 +284,26 @@ public void test_JsonObject__V() throws Exception { invokeTestMethod(instrumented, createJsonObject()); assertTrue(instrumented.hasBeenTraced()); } + + @Test + public void test_ArrayOfJsonObject__V() throws Exception { + ClientCallable_ArrayOfJsonObject__V instrumented = + instrumentClass(ClientCallable_ArrayOfJsonObject__V.class) + .getDeclaredConstructor() + .newInstance(); + invokeTestMethod(instrumented, createArrayOfJsonObject()); + assertTrue(instrumented.hasBeenTraced()); + } + + + @Test + public void test_JsonObjectArgs__V() throws Exception { + ClientCallable_JsonObjectVarargs__V instrumented = + instrumentClass(ClientCallable_JsonObjectVarargs__V.class) + .getDeclaredConstructor() + .newInstance(); + invokeTestMethod(instrumented, createArrayOfJsonObject()); + assertTrue(instrumented.hasBeenTraced()); + } + } diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest24.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest24.java index 881e695..d8aeecd 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest24.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest24.java @@ -24,6 +24,7 @@ import com.vaadin.flow.component.Component; import elemental.json.Json; +import elemental.json.JsonObject; import elemental.json.JsonValue; import org.junit.Rule; import org.junit.rules.ExpectedException; @@ -37,7 +38,7 @@ public class ClientCallablesTest24 extends ClientCallablesTest { @Override protected Class instrumentClass(Class clazz) { for (Class arg : getClientCallableTestMethod(clazz).getParameterTypes()) { - if (JsonValue.class.isAssignableFrom(arg)) { + if (JsonValue.class.isAssignableFrom(arg) || JsonValue[].class.isAssignableFrom(arg)) { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(containsString(ERRMSG)); break; @@ -74,7 +75,13 @@ protected Object createJsonArray() { } @Override - protected Object createJsonObject() { + protected JsonObject createJsonObject() { return Json.createObject(); } + + @Override + protected Object createArrayOfJsonObject() { + return new JsonObject[] {createJsonObject(), createJsonObject()}; + } + } diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest25.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest25.java index 29d3814..adb58d8 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest25.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/ClientCallablesTest25.java @@ -42,7 +42,7 @@ public class ClientCallablesTest25 extends ClientCallablesTest { @Override protected Class instrumentClass(Class clazz) { for (Class arg : getClientCallableTestMethod(clazz).getParameterTypes()) { - if (JsonValue.class.isAssignableFrom(arg)) { + if (JsonValue.class.isAssignableFrom(arg) || JsonValue[].class.isAssignableFrom(arg)) { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(containsString(ERRMSG)); break; @@ -77,7 +77,13 @@ protected Object createJsonArray() { } @Override - protected Object createJsonObject() { + protected ObjectNode createJsonObject() { return new ObjectNode(JsonNodeFactory.instance); } + + @Override + protected Object createArrayOfJsonObject() { + return new ObjectNode[] {createJsonObject(), createJsonObject()}; + } + } diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_ArrayOfJsonObject__V.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_ArrayOfJsonObject__V.java new file mode 100644 index 0000000..3a8d3d1 --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_ArrayOfJsonObject__V.java @@ -0,0 +1,35 @@ +/*- + * #%L + * Json Migration Helper + * %% + * Copyright (C) 2025 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.flowingcode.vaadin.jsonmigration; + +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.not; +import elemental.json.JsonObject; +import org.junit.Assert; + +public class LegacyClientCallable_ArrayOfJsonObject__V extends BaseClientCallable { + + @LegacyClientCallable + public void test(JsonObject[] arg) { + Assert.assertNotNull(arg); + Assert.assertThat(arg, not(emptyArray())); + trace(); + } +} diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_JsonObjectVarargs__V.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_JsonObjectVarargs__V.java new file mode 100644 index 0000000..5e7ccfe --- /dev/null +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallable_JsonObjectVarargs__V.java @@ -0,0 +1,35 @@ +/*- + * #%L + * Json Migration Helper + * %% + * Copyright (C) 2025 Flowing Code + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package com.flowingcode.vaadin.jsonmigration; + +import static org.hamcrest.Matchers.emptyArray; +import static org.hamcrest.Matchers.not; +import elemental.json.JsonObject; +import org.junit.Assert; + +public class LegacyClientCallable_JsonObjectVarargs__V extends BaseClientCallable { + + @LegacyClientCallable + public void test(JsonObject[] arg) { + Assert.assertNotNull(arg); + Assert.assertThat(arg, not(emptyArray())); + trace(); + } +} diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest.java index 4f298c2..580e17a 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest.java @@ -77,6 +77,8 @@ private static Object invokeTestMethod(BaseClientCallable instrumented, Object.. protected abstract Object createJsonObject(); + protected abstract Object createArrayOfJsonObject(); + @Test public void test__V() throws Exception { LegacyClientCallable__V instrumented = @@ -312,4 +314,25 @@ public void test_JsonObject__V() throws Exception { invokeTestMethod(instrumented, createJsonObject()); assertTrue(instrumented.hasBeenTraced()); } + + @Test + public void test_ArrayOfJsonObject__V() throws Exception { + LegacyClientCallable_ArrayOfJsonObject__V instrumented = + instrumentClass(LegacyClientCallable_ArrayOfJsonObject__V.class) + .getDeclaredConstructor() + .newInstance(); + invokeTestMethod(instrumented, createArrayOfJsonObject()); + assertTrue(instrumented.hasBeenTraced()); + } + + @Test + public void test_JsonObjectVarargs__V() throws Exception { + LegacyClientCallable_JsonObjectVarargs__V instrumented = + instrumentClass(LegacyClientCallable_JsonObjectVarargs__V.class) + .getDeclaredConstructor() + .newInstance(); + invokeTestMethod(instrumented, createArrayOfJsonObject()); + assertTrue(instrumented.hasBeenTraced()); + } + } diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest24.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest24.java index 7afbddc..2a7c783 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest24.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest24.java @@ -21,6 +21,7 @@ import com.vaadin.flow.component.Component; import elemental.json.Json; +import elemental.json.JsonObject; public class LegacyClientCallablesTest24 extends LegacyClientCallablesTest { @@ -55,7 +56,13 @@ protected Object createJsonArray() { } @Override - protected Object createJsonObject() { + protected JsonObject createJsonObject() { return Json.createObject(); } + + @Override + protected Object createArrayOfJsonObject() { + return new JsonObject[] {createJsonObject(), createJsonObject()}; + } + } diff --git a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest25.java b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest25.java index f3f1557..7464a9a 100644 --- a/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest25.java +++ b/src/test/java/com/flowingcode/vaadin/jsonmigration/LegacyClientCallablesTest25.java @@ -62,7 +62,13 @@ protected Object createJsonArray() { } @Override - protected Object createJsonObject() { + protected ObjectNode createJsonObject() { return new ObjectNode(JsonNodeFactory.instance); } + + @Override + protected Object createArrayOfJsonObject() { + return new ObjectNode[] {createJsonObject(), createJsonObject()}; + } + }