This is an automated email from the ASF dual-hosted git repository. struberg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git
commit 014ef1e19b25a327c3c7108bab9358ca36bca98c Author: Alexander Falb <[email protected]> AuthorDate: Mon Apr 1 18:29:55 2019 +0200 JOHNZON-206: Tests for nested toStructure mapping Signed-off-by: Mark Struberg <[email protected]> --- .../java/org/apache/johnzon/mapper/MapperTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperTest.java b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperTest.java index 0aa4ccb..45def70 100644 --- a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperTest.java +++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperTest.java @@ -54,6 +54,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonObject; import javax.json.JsonValue; @@ -127,6 +128,36 @@ public class MapperTest { } @Test + public void mapToJsonObject() { + final JsonObject expectedObject = Json.createObjectBuilder().add("a", 1).build(); + final JsonValue structure = new MapperBuilder().build().toStructure(expectedObject); + assertEquals(JsonValue.ValueType.OBJECT, structure.getValueType()); + final JsonObject actualObject = structure.asJsonObject(); + assertEquals("{\"a\":1}", actualObject.toString()); + } + + @Test + public void mapToJsonArrayOfJsonObjects() { + final JsonObject expectedObjectA = Json.createObjectBuilder().add("a", 1).build(); + final JsonObject expectedObjectB = Json.createObjectBuilder().add("b", 2).build(); + final JsonArray expectedArray = Json.createArrayBuilder().add(expectedObjectA).add(expectedObjectB).build(); + final JsonValue structure = new MapperBuilder().build().toStructure(expectedArray); + assertEquals(JsonValue.ValueType.ARRAY, structure.getValueType()); + final JsonArray actualArray = structure.asJsonArray(); + assertEquals("[{\"a\":1},{\"b\":2}]", actualArray.toString()); + } + + @Test + public void mapToArrayOfJsonObjects() { + final JsonObject expectedObjectA = Json.createObjectBuilder().add("a", 1).build(); + final JsonObject expectedObjectB = Json.createObjectBuilder().add("b", 2).build(); + final JsonValue structure = new MapperBuilder().build().toStructure(new Object[]{expectedObjectA, expectedObjectB}); + assertEquals(JsonValue.ValueType.ARRAY, structure.getValueType()); + final JsonArray actualArray = structure.asJsonArray(); + assertEquals("[{\"a\":1},{\"b\":2}]", actualArray.toString()); + } + + @Test public void ignoreAllStrategy() { final StringWriter writer = new StringWriter(); final Child object = new Child();
