-
Notifications
You must be signed in to change notification settings - Fork 0
fix: return class that implement both JsonNode and JsonValue #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalArrayNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
38 changes: 38 additions & 0 deletions
38
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalBooleanNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
32 changes: 32 additions & 0 deletions
32
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalNullNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| } | ||
|
|
32 changes: 32 additions & 0 deletions
32
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalNumberNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } | ||
|
|
56 changes: 56 additions & 0 deletions
56
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalObjectNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
31 changes: 31 additions & 0 deletions
31
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalStringNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/flowingcode/vaadin/jsonmigration/UnsupportedJsonValueImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.