File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
main/java/org/everit/json/schema
java/org/everit/json/schema
resources/org/everit/jsonvalidator/tostring Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .everit .json .schema ;
17
17
18
+ import org .everit .json .schema .internal .JSONPrinter ;
19
+
18
20
import java .util .*;
19
21
import java .util .regex .Pattern ;
20
22
@@ -203,4 +205,14 @@ public int hashCode() {
203
205
protected boolean canEqual (Object other ) {
204
206
return other instanceof StringSchema ;
205
207
}
208
+
209
+ @ Override
210
+ void describePropertiesTo (JSONPrinter writer ) {
211
+ if (requiresString ) {
212
+ writer .key ("type" ).value ("string" );
213
+ }
214
+ writer .ifPresent ("minLength" , minLength );
215
+ writer .ifPresent ("maxLength" , maxLength );
216
+ writer .ifPresent ("pattern" , pattern );
217
+ }
206
218
}
Original file line number Diff line number Diff line change 17
17
18
18
import nl .jqno .equalsverifier .EqualsVerifier ;
19
19
import nl .jqno .equalsverifier .Warning ;
20
+ import org .everit .json .schema .loader .SchemaLoader ;
21
+ import org .json .JSONObject ;
20
22
import org .junit .Assert ;
21
23
import org .junit .Test ;
22
24
23
25
import java .util .Optional ;
24
26
27
+ import static org .junit .Assert .assertTrue ;
28
+
25
29
public class StringSchemaTest {
26
30
27
31
@ Test
@@ -110,4 +114,19 @@ public void equalsVerifier() {
110
114
.suppress (Warning .STRICT_INHERITANCE )
111
115
.verify ();
112
116
}
117
+
118
+ @ Test
119
+ public void toStringTest () {
120
+ JSONObject rawSchemaJson = ResourceLoader .DEFAULT .readObj ("tostring/stringschema.json" );
121
+ String actual = SchemaLoader .load (rawSchemaJson ).toString ();
122
+ assertTrue (ObjectComparator .deepEquals (rawSchemaJson , new JSONObject (actual )));
123
+ }
124
+
125
+ @ Test
126
+ public void toStringNoExplicitType () {
127
+ JSONObject rawSchemaJson = ResourceLoader .DEFAULT .readObj ("tostring/stringschema.json" );
128
+ rawSchemaJson .remove ("type" );
129
+ String actual = SchemaLoader .load (rawSchemaJson ).toString ();
130
+ assertTrue (ObjectComparator .deepEquals (rawSchemaJson , new JSONObject (actual )));
131
+ }
113
132
}
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " string" ,
3
+ "minLength" : 0 ,
4
+ "maxLength" : 10 ,
5
+ "pattern" : " a.b*c"
6
+ }
You can’t perform that action at this time.
0 commit comments