Skip to content

Commit 38c0491

Browse files
committed
feat: implement toJson in UnsupportedJsonValueImpl
1 parent 8945ca8 commit 38c0491

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public ElementalNullNode() {
2828
super();
2929
}
3030

31+
@Override
32+
public String toJson() {
33+
return null;
34+
}
35+
3136
}
3237

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@ public ElementalNumberNode(double value) {
2828
super(value);
2929
}
3030

31+
@Override
32+
public String toJson() {
33+
double value = doubleValue();
34+
if (value == (long) value) {
35+
return String.valueOf((long) value);
36+
} else {
37+
return UnsupportedJsonValueImpl.super.toJson();
38+
}
39+
}
3140
}
3241

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import elemental.json.JsonType;
2323
import elemental.json.JsonValue;
24+
import tools.jackson.databind.JsonNode;
2425

2526
interface UnsupportedJsonValueImpl extends JsonValue {
2627

@@ -46,7 +47,7 @@ default JsonType getType() {
4647

4748
@Override
4849
default String toJson() {
49-
throw new UnsupportedOperationException();
50+
return ((JsonNode) this).toString();
5051
}
5152

5253
@Override

0 commit comments

Comments
 (0)