Skip to content

Commit ae395fb

Browse files
javier-godoypaodb
authored andcommitted
feat: add conversion to JsonNode
1 parent ea81d36 commit ae395fb

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package com.flowingcode.vaadin.jsonmigration;
2121

22+
import com.vaadin.flow.component.ClientCallable;
2223
import com.vaadin.flow.component.page.PendingJavaScriptResult;
2324
import com.vaadin.flow.dom.DomEvent;
2425
import com.vaadin.flow.dom.Element;
@@ -63,6 +64,18 @@ private static Class<?> lookup_BaseJsonNode() {
6364
}
6465
}
6566

67+
/**
68+
* Converts a given Java object into the return type of a {@link ClientCallable method}.
69+
*
70+
* In Vaadin 25, this method converts {@code JsonValue} into {@code JsonNode}.
71+
*
72+
* @param object the object to convert
73+
* @return an {@code Object} suitable to use as the result of a {@code ClientCallable} method.
74+
*/
75+
public static Object convertToClientCallableResult(Object object) {
76+
return helper.convertToClientCallableResult(object);
77+
}
78+
6679
/**
6780
* Converts a given Java object into a {@code JsonValue}.
6881
*

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface JsonMigrationHelper {
2929

3030
JsonValue convertToJsonValue(Object object);
3131

32+
Object convertToClientCallableResult(Object object);
33+
3234
Object invoke(Method method, Object instance, Object... args);
3335

3436
ElementalPendingJavaScriptResult convertPendingJavaScriptResult(PendingJavaScriptResult result);

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper25.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public JsonValue convertToJsonValue(Object object) {
5555
}
5656
}
5757

58+
@Override
59+
public Object convertToClientCallableResult(Object object) {
60+
if (object instanceof JsonValue) {
61+
return convertToJsonNode((JsonValue) object);
62+
} else {
63+
return object;
64+
}
65+
}
66+
5867
@Override
5968
@SneakyThrows
6069
public Object invoke(Method method, Object instance, Object... args) {

src/main/java/com/flowingcode/vaadin/jsonmigration/LegacyJsonMigrationHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public JsonValue convertToJsonValue(Object object) {
3939
object.getClass().getName() + " cannot be converted to elemental.json.JsonObject");
4040
}
4141
}
42+
43+
@Override
44+
public Object convertToClientCallableResult(Object object) {
45+
return object;
46+
}
4247

4348
@Override
4449
@SneakyThrows

0 commit comments

Comments
 (0)