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
@@ -0,0 +1,53 @@
/*-
* #%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 elemental.json.JsonArray;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.JsonNodeFactory;

@SuppressWarnings("serial")
class ElementalArrayNode extends ArrayNode implements UnsupportedJsonValueImpl {

public ElementalArrayNode(JsonArray a) {
super(JsonNodeFactory.instance, children(a));
}

private static List<JsonNode> children(JsonArray a) {
switch (a.length()) {
case 0:
return Collections.emptyList();
case 1:
return Collections.singletonList(JsonMigrationHelper25.convertToJsonNode(a.get(0)));
default:
List<JsonNode> children = new ArrayList<>(a.length());
for (int i = 0, n = a.length(); i < n; i++) {
children.add(JsonMigrationHelper25.convertToJsonNode(a.get(i)));
}
return children;
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*-
* #%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 tools.jackson.databind.node.BooleanNode;

@SuppressWarnings("serial")
class ElementalBooleanNode extends BooleanNode implements UnsupportedJsonValueImpl {

public ElementalBooleanNode(boolean value) {
super(value);
}

}







Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*-
* #%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 tools.jackson.databind.node.NullNode;

@SuppressWarnings("serial")
class ElementalNullNode extends NullNode implements UnsupportedJsonValueImpl {

public ElementalNullNode() {
super();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*-
* #%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 tools.jackson.databind.node.DoubleNode;

@SuppressWarnings("serial")
class ElementalNumberNode extends DoubleNode implements UnsupportedJsonValueImpl {

public ElementalNumberNode(double value) {
super(value);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*-
* #%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 com.flowingcode.vaadin.jsonmigration.JsonMigrationHelper25.convertToJsonNode;
import elemental.json.JsonObject;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.node.ObjectNode;

@SuppressWarnings("serial")
class ElementalObjectNode extends ObjectNode implements UnsupportedJsonValueImpl {

public ElementalObjectNode(JsonObject o) {
super(JsonNodeFactory.instance, children(o));
}

private static Map<String, JsonNode> children(JsonObject o) {
String keys[] = o.keys();
switch (keys.length) {
case 0:
return Collections.emptyMap();
case 1:
return Collections.singletonMap(keys[0], convertToJsonNode(o.get(keys[0])));
default:
Map<String, JsonNode> children = new LinkedHashMap<>(keys.length);
for (String key : keys) {
children.put(key, convertToJsonNode(o.get(key)));
}
return children;
}
}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*-
* #%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 tools.jackson.databind.node.StringNode;

@SuppressWarnings("serial")
class ElementalStringNode extends StringNode implements UnsupportedJsonValueImpl {

public ElementalStringNode(String value) {
super(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static Class<?> lookup_BaseJsonNode() {
* @param object the object to convert
* @return an {@code Object} suitable to use as the result of a {@code ClientCallable} method.
*/
public static Object convertToClientCallableResult(Object object) {
public static <T extends JsonValue> T convertToClientCallableResult(T object) {
return helper.convertToClientCallableResult(object);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface JsonMigrationHelper {

JsonValue convertToJsonValue(Object object);

Object convertToClientCallableResult(Object object);
<T extends JsonValue> T convertToClientCallableResult(T object);

Object invoke(Method method, Object instance, Object... args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,28 @@ public JsonValue convertToJsonValue(Object object) {
}
}

@SuppressWarnings("unchecked")
@Override
public Object convertToClientCallableResult(Object object) {
if (object instanceof JsonValue) {
return convertToJsonNode((JsonValue) object);
public JsonValue convertToClientCallableResult(JsonValue object) {
if (object == null) {
return null;
} else {
return object;
switch (object.getType()) {
case OBJECT:
return new ElementalObjectNode((JsonObject) object);
case ARRAY:
return new ElementalArrayNode((JsonArray) object);
case BOOLEAN:
return new ElementalBooleanNode(object.asBoolean());
case NULL:
return new ElementalNullNode();
case NUMBER:
return new ElementalNumberNode(object.asNumber());
case STRING:
return new ElementalStringNode(object.asString());
default:
throw new IllegalArgumentException();
}
}
}

Expand Down Expand Up @@ -155,7 +171,7 @@ private static JsonValue convertToJsonValue(JsonNode jsonNode) {

private static final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;

private static BaseJsonNode convertToJsonNode(JsonValue jsonValue) {
static BaseJsonNode convertToJsonNode(JsonValue jsonValue) {
switch (jsonValue.getType()) {
case OBJECT:
JsonObject jsonObject = (JsonObject) jsonValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public JsonValue convertToJsonValue(Object object) {
}

@Override
public Object convertToClientCallableResult(Object object) {
public <T extends JsonValue> T convertToClientCallableResult(T object) {
return object;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*-
* #%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 elemental.json.JsonType;
import elemental.json.JsonValue;

interface UnsupportedJsonValueImpl extends JsonValue {

@Override
default boolean asBoolean() {
throw new UnsupportedOperationException();
}

@Override
default double asNumber() {
throw new UnsupportedOperationException();
}

@Override
default String asString() {
throw new UnsupportedOperationException();
}

@Override
default JsonType getType() {
throw new UnsupportedOperationException();
}

@Override
default String toJson() {
throw new UnsupportedOperationException();
}

@Override
default boolean jsEquals(JsonValue value) {
throw new UnsupportedOperationException();
}

@Override
default Object toNative() {
throw new UnsupportedOperationException();
}

}