File tree Expand file tree Collapse file tree 4 files changed +33
-15
lines changed
main/java/org/everit/json/schema
test/java/org/everit/json/schema/internal Expand file tree Collapse file tree 4 files changed +33
-15
lines changed Original file line number Diff line number Diff line change @@ -467,12 +467,7 @@ void describePropertiesTo(JSONPrinter writer) {
467
467
}
468
468
if (!propertySchemas .isEmpty ()) {
469
469
writer .key ("properties" );
470
- writer .object ();
471
- propertySchemas .entrySet ().forEach (entry -> {
472
- writer .key (entry .getKey ());
473
- entry .getValue ().describeTo (writer );
474
- });
475
- writer .endObject ();
470
+ writer .printSchemaMap (propertySchemas );
476
471
}
477
472
writer .ifPresent ("minProperties" , minProperties );
478
473
writer .ifPresent ("maxProperties" , maxProperties );
@@ -488,12 +483,7 @@ void describePropertiesTo(JSONPrinter writer) {
488
483
}
489
484
if (!patternProperties .isEmpty ()) {
490
485
writer .key ("patternProperties" );
491
- writer .object ();
492
- patternProperties .entrySet ().forEach (entry -> {
493
- writer .key (entry .getKey ().toString ());
494
- entry .getValue ().describeTo (writer );
495
- });
496
- writer .endObject ();
486
+ writer .printSchemaMap (patternProperties );
497
487
}
498
488
}
499
489
Original file line number Diff line number Diff line change @@ -165,11 +165,16 @@ public String getId() {
165
165
}
166
166
167
167
/**
168
- * <<<<<<< HEAD Describes the instance as a JSONObject to {@code writer}.
168
+ * Describes the instance as a JSONObject to {@code writer}.
169
+ *
170
+ * First it adds the {@code "title} , {@code "description"} and {@code "id"} properties then calls
171
+ * {@link #describePropertiesTo(JSONPrinter)}, which will add the subclass-specific properties.
172
+ *
173
+ * It is used by {@link #toString()} to serialize the schema instance into its JSON representation.
169
174
*
170
175
* @param writer it will receive the schema description
171
176
*/
172
- final void describeTo (final JSONPrinter writer ) {
177
+ public final void describeTo (final JSONPrinter writer ) {
173
178
writer .object ();
174
179
writer .ifPresent ("title" , title );
175
180
writer .ifPresent ("description" , description );
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema .internal ;
2
2
3
+ import org .everit .json .schema .Schema ;
3
4
import org .json .JSONWriter ;
4
5
5
6
import java .io .Writer ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
6
9
7
10
import static java .util .Objects .requireNonNull ;
8
11
@@ -70,4 +73,13 @@ public void ifFalse(String key, Boolean value) {
70
73
writer .value (value );
71
74
}
72
75
}
76
+
77
+ public <K > void printSchemaMap (Map <K , Schema > input ) {
78
+ object ();
79
+ input .entrySet ().forEach (entry -> {
80
+ key (entry .getKey ().toString ());
81
+ entry .getValue ().describeTo (this );
82
+ });
83
+ endObject ();
84
+ }
73
85
}
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema .internal ;
2
2
3
+ import org .everit .json .schema .NullSchema ;
4
+ import org .everit .json .schema .Schema ;
3
5
import org .json .JSONObject ;
4
6
import org .json .JSONWriter ;
5
7
import org .junit .Before ;
6
8
import org .junit .Ignore ;
7
9
import org .junit .Test ;
8
10
9
11
import java .io .StringWriter ;
12
+ import java .util .HashMap ;
10
13
11
14
import static org .junit .Assert .assertEquals ;
12
15
import static org .junit .Assert .assertNull ;
@@ -106,7 +109,7 @@ public void ifFalseOmits() {
106
109
assertNull (actualObj ().opt ("mykey" ));
107
110
}
108
111
109
- @ Test @ Ignore
112
+ @ Test
110
113
public void ifFalseHandlesNullAsTrue () {
111
114
JSONPrinter subject = subject ();
112
115
subject .object ();
@@ -124,4 +127,12 @@ public void arraySupport() {
124
127
assertEquals ("[true]" , buffer .toString ());
125
128
}
126
129
130
+ @ Test
131
+ public void printSchemaMap () {
132
+ HashMap <Number , Schema > input = new HashMap <Number , Schema >();
133
+ input .put (2 , NullSchema .INSTANCE );
134
+ subject ().printSchemaMap (input );
135
+ assertEquals ("{\" 2\" :" +NullSchema .INSTANCE .toString () + "}" , buffer .toString ());
136
+ }
137
+
127
138
}
You can’t perform that action at this time.
0 commit comments