-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[json-node] Make JsonNode Serializable
- Loading branch information
Showing
10 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
37 changes: 37 additions & 0 deletions
37
json-node/src/test/java/io/avaje/json/node/SerializeTest.java
This file contains 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,37 @@ | ||
package io.avaje.json.node; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.*; | ||
import java.math.BigDecimal; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class SerializeTest { | ||
|
||
@Test | ||
void test() throws IOException, ClassNotFoundException { | ||
|
||
Boolean.valueOf(true); | ||
final var source = JsonArray.create() | ||
.add("foo") | ||
.add(JsonObject.create() | ||
.add("aStr", "a") | ||
.add("aBool", true) | ||
.add("aInt", 42) | ||
.add("aLong", 420L) | ||
.add("aDouble", JsonDouble.of(4204.3D)) | ||
.add("aDecimal", JsonDecimal.of(BigDecimal.TEN)) | ||
); | ||
|
||
var baos = new ByteArrayOutputStream(); | ||
try (var oos = new ObjectOutputStream(baos)) { | ||
oos.writeObject(source); | ||
} | ||
|
||
var ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); | ||
var readO = ois.readObject(); | ||
|
||
assertThat(readO).isInstanceOf(JsonArray.class); | ||
assertThat(readO).isEqualTo(source); | ||
} | ||
} |