From a0796cfe80f1e071153b346a059893eadea38cf8 Mon Sep 17 00:00:00 2001 From: idelvall Date: Mon, 14 Oct 2013 13:25:17 +0200 Subject: [PATCH 1/5] Update ObjectSchema.java Schemas with additional properties were not properly serialized. --- .../jackson/module/jsonSchema/types/ObjectSchema.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java index a9c2baec..11920d65 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java @@ -237,6 +237,7 @@ public boolean equals(Object obj) { getJsonSchema().equals(((SchemaAdditionalProperties)obj).getJsonSchema()); } + @JsonValue public JsonSchema getJsonSchema() { return jsonSchema; } @@ -333,4 +334,4 @@ public String getDependsOn() { } } -} \ No newline at end of file +} From 967afec16f1aa982f1fc104649cf4aff81c3ab33 Mon Sep 17 00:00:00 2001 From: idelvall Date: Mon, 14 Oct 2013 13:35:08 +0200 Subject: [PATCH 2/5] Update MapVisitor.java https://github.com/FasterXML/jackson-module-jsonSchema/issues/24 --- .../jsonSchema/factories/MapVisitor.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java index 30058026..b662edfe 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonMapFormatVisitor; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema; /** @@ -58,10 +59,21 @@ public void keyFormat(JsonFormatVisitable handler, JavaType keyType) // JSON Schema only allows String types so let's not bother too much } - @Override + @Override public void valueFormat(JsonFormatVisitable handler, JavaType valueType) throws JsonMappingException { - /* Also... not sure what to do with value type either. - */ + + // ISSUE #24: https://github.com/FasterXML/jackson-module-jsonSchema/issues/24 + + JsonSchema valueSchema = propertySchema(handler, valueType); + ObjectSchema.AdditionalProperties ap = new ObjectSchema.SchemaAdditionalProperties(valueSchema.asSimpleTypeSchema()); + this.schema.setAdditionalProperties(ap); + } + + protected JsonSchema propertySchema(JsonFormatVisitable handler, JavaType propertyTypeHint) + throws JsonMappingException { + SchemaFactoryWrapper visitor = wrapperFactory.getWrapper(getProvider()); + handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); + return visitor.finalSchema(); } } From 0bc68da9ee4d955c69f570cfd54ef641eb2b1c6c Mon Sep 17 00:00:00 2001 From: idelvall Date: Tue, 15 Oct 2013 06:17:36 -0700 Subject: [PATCH 3/5] --- .../jsonSchema/factories/MapVisitor.java | 2 + .../AdditionalPropertiesDeserializer.java | 56 +++++ .../module/jsonSchema/types/ObjectSchema.java | 3 + .../jsonSchema/TestGenerateJsonSchema.java | 235 +++++++++--------- .../module/jsonSchema/TestReadJsonSchema.java | 59 +++-- 5 files changed, 225 insertions(+), 130 deletions(-) create mode 100644 src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AdditionalPropertiesDeserializer.java diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java index b662edfe..55eb37a3 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/factories/MapVisitor.java @@ -20,6 +20,8 @@ public class MapVisitor extends JsonMapFormatVisitor.Base protected SerializerProvider provider; + private WrapperFactory wrapperFactory = new WrapperFactory(); + public MapVisitor(SerializerProvider provider, ObjectSchema schema) { this.provider = provider; diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AdditionalPropertiesDeserializer.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AdditionalPropertiesDeserializer.java new file mode 100644 index 00000000..13145d55 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/AdditionalPropertiesDeserializer.java @@ -0,0 +1,56 @@ +/* + * Copyright 2013 FasterXML. + * + * 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. + */ +package com.fasterxml.jackson.module.jsonSchema.types; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.module.jsonSchema.JsonSchema; +import java.io.IOException; + +/** + * + * @author Ignacio del Valle Alles + */ +public class AdditionalPropertiesDeserializer extends JsonDeserializer { + + @Override + public ObjectSchema.AdditionalProperties deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { + ObjectMapper mapper = (ObjectMapper) jp.getCodec(); + TreeNode node = mapper.readTree(jp); + String nodeStr = mapper.writeValueAsString(node); + if (node instanceof ObjectNode) { + JsonSchema innerSchema = mapper.readValue(nodeStr, JsonSchema.class); + return new ObjectSchema.SchemaAdditionalProperties(innerSchema); + } else if (node instanceof BooleanNode) { + BooleanNode booleanNode = (BooleanNode) node; + if (booleanNode.booleanValue()) { + return null; // "additionalProperties":true is the default + } else { + return ObjectSchema.NoAdditionalProperties.instance; + } + } else { + throw new JsonMappingException("additionalProperties nodes can only be of " + + "type boolean or object: " + nodeStr); + } + } +} diff --git a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java index 11920d65..c14bc0c4 100644 --- a/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes; import com.fasterxml.jackson.module.jsonSchema.JsonSchema; @@ -184,6 +185,7 @@ public void setProperties(Map properties) { this.properties = properties; } + @JsonDeserialize(using = AdditionalPropertiesDeserializer.class) public static abstract class AdditionalProperties { @JsonCreator public AdditionalProperties jsonCreator() { @@ -222,6 +224,7 @@ public Boolean value() { public static final NoAdditionalProperties instance = new NoAdditionalProperties(); } + public static class SchemaAdditionalProperties extends AdditionalProperties { @JsonProperty diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java index 47cb90fb..287aa822 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestGenerateJsonSchema.java @@ -17,127 +17,127 @@ @SuppressWarnings("serial") public class TestGenerateJsonSchema - extends SchemaTestBase -{ + extends SchemaTestBase { /* - /********************************************************** - /* Helper classes - /********************************************************** + /********************************************************** + /* Helper classes + /********************************************************** */ - public static class SimpleBean - { + public static class SimpleBean { + private int property1; private String property2; private String[] property3; private Collection property4; @JsonProperty(required = true) private String property5; - - public int getProperty1() - { + + public int getProperty1() { return property1; } - public void setProperty1(int property1) - { + public void setProperty1(int property1) { this.property1 = property1; } - public String getProperty2() - { + public String getProperty2() { return property2; } - public void setProperty2(String property2) - { + public void setProperty2(String property2) { this.property2 = property2; } - public String[] getProperty3() - { + public String[] getProperty3() { return property3; } - public void setProperty3(String[] property3) - { + public void setProperty3(String[] property3) { this.property3 = property3; } - public Collection getProperty4() - { + public Collection getProperty4() { return property4; } - public void setProperty4(Collection property4) - { + public void setProperty4(Collection property4) { this.property4 = property4; } - - public String getProperty5() - { + + public String getProperty5() { return property5; } - public void setProperty5(String property5) - { + public void setProperty5(String property5) { this.property5 = property5; } } public class TrivialBean { + public String name; } //@JsonSerializableSchema(id="myType") public static class BeanWithId { + public String value; } @JsonFilter("filteredBean") protected static class FilteredBean { + @JsonProperty private String secret = "secret"; - @JsonProperty private String obvious = "obvious"; - - public String getSecret() { return secret; } - public void setSecret(String s) { secret = s; } - - public String getObvious() { return obvious; } - public void setObvious(String s) {obvious = s; } + + public String getSecret() { + return secret; + } + + public void setSecret(String s) { + secret = s; + } + + public String getObvious() { + return obvious; + } + + public void setObvious(String s) { + obvious = s; + } } - public static FilterProvider secretFilterProvider = new SimpleFilterProvider() - .addFilter("filteredBean", SimpleBeanPropertyFilter.filterOutAllExcept(new String[]{"obvious"})); + .addFilter("filteredBean", SimpleBeanPropertyFilter.filterOutAllExcept(new String[]{"obvious"})); public enum Enumerated { + A, B, C; } - + public static class LetterBean { + public Enumerated letter; } - static class StringMap extends HashMap { } - + static class StringMap extends HashMap { + } /* - /********************************************************** - /* Unit tests, success - /********************************************************** + /********************************************************** + /* Unit tests, success + /********************************************************** */ - private final ObjectMapper MAPPER = new ObjectMapper(); - + /** * Test simple generation */ - public void testGeneratingJsonSchema() throws Exception - { + public void testGeneratingJsonSchema() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(SimpleBean.class); - + assertNotNull(jsonSchema); // test basic equality, and that equals() handles null, other obs @@ -148,18 +148,18 @@ public void testGeneratingJsonSchema() throws Exception assertTrue(jsonSchema.isObjectSchema()); ObjectSchema object = jsonSchema.asObjectSchema(); assertNotNull(object); - Map properties = object.getProperties(); + Map properties = object.getProperties(); assertNotNull(properties); JsonSchema prop1 = properties.get("property1"); assertNotNull(prop1); assertTrue(prop1.isIntegerSchema()); assertNull(prop1.getRequired()); - + JsonSchema prop2 = properties.get("property2"); assertNotNull(prop2); assertTrue(prop2.isStringSchema()); assertNull(prop2.getRequired()); - + JsonSchema prop3 = properties.get("property3"); assertNotNull(prop3); assertTrue(prop3.isArraySchema()); @@ -169,7 +169,7 @@ public void testGeneratingJsonSchema() throws Exception JsonSchema itemType = items.asSingleItems().getSchema(); assertNotNull(itemType); assertTrue(itemType.isStringSchema()); - + JsonSchema prop4 = properties.get("property4"); assertNotNull(prop4); assertTrue(prop4.isArraySchema()); @@ -179,15 +179,14 @@ public void testGeneratingJsonSchema() throws Exception itemType = items.asSingleItems().getSchema(); assertNotNull(itemType); assertTrue(itemType.isNumberSchema()); - + JsonSchema prop5 = properties.get("property5"); assertNotNull(prop5); assertTrue(prop5.getRequired()); - + } - public void testGeneratingJsonSchemaWithFilters() throws Exception - { + public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper); @@ -196,23 +195,22 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception assertTrue(jsonSchema.isObjectSchema()); ObjectSchema object = jsonSchema.asObjectSchema(); assertNotNull(object); - Map properties = object.getProperties(); - assertNotNull(properties); - JsonSchema obvious = properties.get("obvious"); - assertNotNull(obvious); - assertTrue(obvious.isStringSchema()); - assertNull(properties.get("secret")); + Map properties = object.getProperties(); + assertNotNull(properties); + JsonSchema obvious = properties.get("obvious"); + assertNotNull(obvious); + assertTrue(obvious.isStringSchema()); + assertNull(properties.get("secret")); } /** - * Additional unit test for verifying that schema object itself - * can be properly serialized + * Additional unit test for verifying that schema object itself can be + * properly serialized */ - public void testSchemaSerialization() throws Exception - { + public void testSchemaSerialization() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(SimpleBean.class); - Map result = writeAndMap(MAPPER, jsonSchema); + Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); // no need to check out full structure, just basics... assertEquals("object", result.get("type")); @@ -224,75 +222,86 @@ public void testSchemaSerialization() throws Exception /** * Test for [JACKSON-454] */ - public void testThatObjectsHaveNoItems() throws Exception - { + public void testThatObjectsHaveNoItems() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(TrivialBean.class); - Map result = writeAndMap(MAPPER, jsonSchema); + Map result = writeAndMap(MAPPER, jsonSchema); // can we count on ordering being stable? I think this is true with current ObjectNode impl // as perh [JACKSON-563]; 'required' is only included if true assertFalse(result.containsKey("items")); } - @SuppressWarnings({ "unchecked", "rawtypes" }) - public void testSchemaId() throws Exception - { + @SuppressWarnings({"unchecked", "rawtypes"}) + public void testSchemaId() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(BeanWithId.class); - Map result = writeAndMap(MAPPER, jsonSchema); - - assertEquals(new HashMap() {{ - put("type", "object"); - put("properties", - new HashMap(){{ put("value", - new HashMap() {{ put("type", "string"); }} - ); - }} - ); - }}, result); + Map result = writeAndMap(MAPPER, jsonSchema); + + assertEquals(new HashMap() { + { + put("type", "object"); + put("properties", + new HashMap() { + { + put("value", + new HashMap() { + { + put("type", "string"); + } + }); + } + }); + } + }, result); } - public void testWithEnum() throws Exception - { + public void testWithEnum() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(LetterBean.class); - Map result = writeAndMap(MAPPER, jsonSchema); + Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); - - assertEquals(new HashMap() {{ - put("type", "object"); - put("properties", - new HashMap(){{ put("letter", - new HashMap() {{ + + assertEquals(new HashMap() { + { + put("type", "object"); + put("properties", + new HashMap() { + { + put("letter", + new HashMap() { + { put("type", "string"); - put("enum", new ArrayList() {{ - add("A"); add("B"); add("C"); - }} ); - }} ); - }} - ); - }}, result); + put("enum", new ArrayList() { + { + add("A"); + add("B"); + add("C"); + } + }); + } + }); + } + }); + } + }, result); } - public void testSimpleMap() throws Exception - { + public void testSimpleMap() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); JsonSchema jsonSchema = generator.generateSchema(StringMap.class); - Map result = writeAndMap(MAPPER, jsonSchema); + Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); - // Maps are treated like ... "empty" Object. Not good, should be improved if possible - assertEquals("{\"type\":\"object\"}", MAPPER.writeValueAsString(jsonSchema)); + String mapSchemaStr = MAPPER.writeValueAsString(jsonSchema); + assertEquals("{\"type\":\"object\",\"additionalProperties\":{\"type\":\"string\"}}", mapSchemaStr); } - + /* - /********************************************************** - /* Tests cases, error detection/handling - /********************************************************** + /********************************************************** + /* Tests cases, error detection/handling + /********************************************************** */ - - public void testInvalidCall() throws Exception - { + public void testInvalidCall() throws Exception { // not ok to pass null try { SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java index f394905d..5dd3cf05 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.module.jsonSchema; +import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; import java.util.EnumMap; import java.util.EnumSet; @@ -10,51 +11,48 @@ import com.fasterxml.jackson.databind.JsonSerializable; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; +import com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema; /** * Trivial test to ensure {@link JsonSchema} can be also deserialized */ public class TestReadJsonSchema - extends SchemaTestBase -{ - enum SchemaEnum { YES, NO; } + extends SchemaTestBase { + + enum SchemaEnum { + + YES, NO; + } static class Schemable { + public String name; public char[] nameBuffer; - // We'll include tons of stuff, just to force generation of schema public boolean[] states; public byte[] binaryData; public short[] shorts; public int[] ints; public long[] longs; - public float[] floats; public double[] doubles; - public Object[] objects; public JsonSerializable someSerializable; - public Iterable iterableOhYeahBaby; - public List extra; public ArrayList extra2; public Iterator extra3; - - public Map sizes; - public EnumMap> whatever; - + public Map> mapSizes; + public EnumMap> whatever; SchemaEnum testEnum; public EnumSet testEnums; } /** - * Verifies that a simple schema that is serialized can be - * deserialized back to equal schema instance + * Verifies that a simple schema that is serialized can be deserialized back + * to equal schema instance */ - public void testDeserializeSimple() throws Exception - { + public void testDeserializeSimple() throws Exception { ObjectMapper mapper = new ObjectMapper(); SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); mapper.acceptJsonFormatVisitor(mapper.constructType(Schemable.class), visitor); @@ -64,6 +62,33 @@ public void testDeserializeSimple() throws Exception String schemaStr = mapper.writeValueAsString(jsonSchema); assertNotNull(schemaStr); JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class); - assertEquals("Trying to read from '"+schemaStr+"'", jsonSchema, result); + assertEquals("Trying to read from '" + schemaStr + "'", jsonSchema, result); + } + + /** + * Verifies that a false-valued and object-valued additional properties are + * deserialized properly + */ + public void testDeserializeFalseAndObjectAdditionalProperties() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String schemaStr = "{\"type\":\"object\",\"properties\":{\"mapSizes\":{\"type\":\"object\",\"additionalProperties\":{\"type\":\"number\"}}},\"additionalProperties\":false}"; + JsonSchema schema = mapper.readValue(schemaStr, JsonSchema.class); + String newSchemaStr = mapper.writeValueAsString(schema); + assertEquals(schemaStr.replaceAll("\\s", "").length(), newSchemaStr.replaceAll("\\s", "").length()); + JsonNode node = mapper.readTree(schemaStr); + JsonNode finalNode = mapper.readTree(newSchemaStr); + assertEquals(node, finalNode); + } + + /** + * Verifies that a false-valued and object-valued additional properties are + * deserialized properly + */ + public void testDeserializeTrueAdditionalProperties() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + String schemaStr = "{\"type\":\"object\",\"additionalProperties\":true}"; + ObjectSchema schema = mapper.readValue(schemaStr, ObjectSchema.class); + assertNull(schema.getAdditionalProperties()); + } } From 0a7a92f4d55d4c9ece5e87d000b9d31a835333ab Mon Sep 17 00:00:00 2001 From: idelvall Date: Tue, 15 Oct 2013 06:21:59 -0700 Subject: [PATCH 4/5] --- .../jackson/module/jsonSchema/TestReadJsonSchema.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java index 5dd3cf05..70525c00 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java @@ -66,7 +66,7 @@ public void testDeserializeSimple() throws Exception { } /** - * Verifies that a false-valued and object-valued additional properties are + * Verifies that false-valued and object-valued additional properties are * deserialized properly */ public void testDeserializeFalseAndObjectAdditionalProperties() throws Exception { @@ -81,7 +81,7 @@ public void testDeserializeFalseAndObjectAdditionalProperties() throws Exception } /** - * Verifies that a false-valued and object-valued additional properties are + * Verifies that a true-valued additional property is * deserialized properly */ public void testDeserializeTrueAdditionalProperties() throws Exception { From d2c8cf7ea589d483a143b0c2abab2f8c4ebdc72d Mon Sep 17 00:00:00 2001 From: Ignacio del Valle Alles Date: Tue, 15 Oct 2013 06:49:11 -0700 Subject: [PATCH 5/5] --- .../jackson/module/jsonSchema/TestReadJsonSchema.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java index 70525c00..95ae83bc 100644 --- a/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/module/jsonSchema/TestReadJsonSchema.java @@ -62,7 +62,10 @@ public void testDeserializeSimple() throws Exception { String schemaStr = mapper.writeValueAsString(jsonSchema); assertNotNull(schemaStr); JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class); - assertEquals("Trying to read from '" + schemaStr + "'", jsonSchema, result); + String resultStr = mapper.writeValueAsString(result); + JsonNode node = mapper.readTree(schemaStr); + JsonNode finalNode = mapper.readTree(resultStr); + assertEquals(node, finalNode); } /** @@ -75,14 +78,14 @@ public void testDeserializeFalseAndObjectAdditionalProperties() throws Exception JsonSchema schema = mapper.readValue(schemaStr, JsonSchema.class); String newSchemaStr = mapper.writeValueAsString(schema); assertEquals(schemaStr.replaceAll("\\s", "").length(), newSchemaStr.replaceAll("\\s", "").length()); + JsonNode node = mapper.readTree(schemaStr); JsonNode finalNode = mapper.readTree(newSchemaStr); assertEquals(node, finalNode); } /** - * Verifies that a true-valued additional property is - * deserialized properly + * Verifies that a true-valued additional property is deserialized properly */ public void testDeserializeTrueAdditionalProperties() throws Exception { ObjectMapper mapper = new ObjectMapper();