Skip to content

Commit 51915dd

Browse files
committed
fixing #345
1 parent b735b39 commit 51915dd

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

core/src/main/java/org/everit/json/schema/ToStringVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ void visitBooleanSchema(BooleanSchema schema) {
144144

145145
@Override void visitNotSchema(NotSchema notSchema) {
146146
printInJsonObject(() -> {
147+
visitSchema(notSchema);
147148
writer.key("not");
148-
super.visitNotSchema(notSchema);
149+
notSchema.getMustNotMatch().accept(this);
149150
});
150151
}
151152

core/src/test/java/org/everit/json/schema/NotSchemaTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@
1515
*/
1616
package org.everit.json.schema;
1717

18+
import static org.everit.json.schema.JSONMatcher.sameJsonAs;
1819
import static org.everit.json.schema.TestSupport.buildWithLocation;
20+
import static org.hamcrest.MatcherAssert.assertThat;
1921
import static org.junit.Assert.assertEquals;
2022

23+
import org.everit.json.schema.loader.SchemaLoader;
24+
import org.json.JSONObject;
2125
import org.junit.Test;
2226

2327
import nl.jqno.equalsverifier.EqualsVerifier;
2428
import nl.jqno.equalsverifier.Warning;
2529

2630
public class NotSchemaTest {
2731

32+
private static final ResourceLoader LOADER = ResourceLoader.DEFAULT;
33+
2834
@Test
2935
public void failure() {
3036
NotSchema subject = buildWithLocation(NotSchema.builder().mustNotMatch(BooleanSchema.INSTANCE));
@@ -57,4 +63,13 @@ public void toStringTest() {
5763
assertEquals("{\"not\":{\"type\":\"boolean\"}}", actual);
5864
}
5965

66+
@Test
67+
public void issue345() {
68+
JSONObject rawSchema = LOADER.readObj("issue345.json");
69+
Schema notSchema = SchemaLoader.builder()
70+
.schemaJson(rawSchema)
71+
.build().load().build();
72+
assertThat(new JSONObject(notSchema.toString()), sameJsonAs(rawSchema));
73+
}
74+
6075
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema":"http://json-schema.org/draft-04/schema#",
3+
"not":{
4+
"type":"object",
5+
"properties":{
6+
"name":{
7+
"type":"string"
8+
}
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)