Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ private List<Method> 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;
}
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +38,7 @@ public class ClientCallablesTest24 extends ClientCallablesTest {
@Override
protected <T extends Component> Class<? extends T> instrumentClass(Class<T> 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;
Expand Down Expand Up @@ -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()};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ClientCallablesTest25 extends ClientCallablesTest {
@Override
protected <T extends Component> Class<? extends T> instrumentClass(Class<T> 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;
Expand Down Expand Up @@ -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()};
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.vaadin.flow.component.Component;
import elemental.json.Json;
import elemental.json.JsonObject;

public class LegacyClientCallablesTest24 extends LegacyClientCallablesTest {

Expand Down Expand Up @@ -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()};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()};
}

}