2
2
3
3
import com .fasterxml .jackson .annotation .JsonFilter ;
4
4
import com .fasterxml .jackson .annotation .JsonProperty ;
5
+ import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
5
6
import com .fasterxml .jackson .databind .JavaType ;
7
+ import com .fasterxml .jackson .databind .MapperFeature ;
6
8
import com .fasterxml .jackson .databind .ObjectMapper ;
7
9
import com .fasterxml .jackson .databind .ser .FilterProvider ;
8
10
import com .fasterxml .jackson .databind .ser .impl .SimpleBeanPropertyFilter ;
19
21
public class TestGenerateJsonSchema
20
22
extends SchemaTestBase
21
23
{
24
+ @ JsonPropertyOrder ({"property1" , "property2" , "property3" , "property4" , "property5" })
22
25
public static class SimpleBean
23
26
{
24
27
private int property1 ;
@@ -272,17 +275,19 @@ public void testSimpleMap() throws Exception {
272
275
}
273
276
274
277
public void testSinglePropertyDependency () throws Exception {
275
- JsonSchemaGenerator generator = new JsonSchemaGenerator (MAPPER );
278
+ ObjectMapper mapper = new ObjectMapper ();
279
+ mapper .configure (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true );
280
+ JsonSchemaGenerator generator = new JsonSchemaGenerator (mapper );
276
281
JsonSchema jsonSchema = generator .generateSchema (SimpleBean .class );
277
282
((ObjectSchema ) jsonSchema ).addSimpleDependency ("property1" , "property2" );
278
283
279
- Map <String , Object > result = writeAndMap (MAPPER , jsonSchema );
284
+ Map <String , Object > result = writeAndMap (mapper , jsonSchema );
280
285
assertNotNull (result );
281
-
282
- String schemaString = MAPPER .writeValueAsString (jsonSchema );
286
+
287
+ String schemaString = mapper .writeValueAsString (jsonSchema );
283
288
assertEquals ("{\" type\" :\" object\" ," +
284
- "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
285
289
"\" dependencies\" :{\" property1\" :[\" property2\" ]}," +
290
+ "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
286
291
"\" properties\" :{\" property1\" :{\" type\" :\" integer\" }" +
287
292
",\" property2\" :{\" type\" :\" string\" }," +
288
293
"\" property3\" :{\" type\" :\" array\" ,\" items\" :{\" type\" :\" string\" }}," +
@@ -291,20 +296,22 @@ public void testSinglePropertyDependency() throws Exception {
291
296
}
292
297
293
298
public void testMultiplePropertyDependencies () throws Exception {
294
- JsonSchemaGenerator generator = new JsonSchemaGenerator (MAPPER );
299
+ ObjectMapper mapper = new ObjectMapper ();
300
+ mapper .configure (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true );
301
+ JsonSchemaGenerator generator = new JsonSchemaGenerator (mapper );
295
302
JsonSchema jsonSchema = generator .generateSchema (SimpleBean .class );
296
303
((ObjectSchema ) jsonSchema ).addSimpleDependency ("property1" , "property2" );
297
304
((ObjectSchema ) jsonSchema ).addSimpleDependency ("property1" , "property3" );
298
305
((ObjectSchema ) jsonSchema ).addSimpleDependency ("property1" , "property2" );
299
306
((ObjectSchema ) jsonSchema ).addSimpleDependency ("property2" , "property3" );
300
307
301
- Map <String , Object > result = writeAndMap (MAPPER , jsonSchema );
308
+ Map <String , Object > result = writeAndMap (mapper , jsonSchema );
302
309
assertNotNull (result );
303
310
304
- String schemaString = MAPPER .writeValueAsString (jsonSchema );
311
+ String schemaString = mapper .writeValueAsString (jsonSchema );
305
312
assertEquals ("{\" type\" :\" object\" ," +
306
- "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
307
313
"\" dependencies\" :{\" property1\" :[\" property2\" ,\" property3\" ],\" property2\" :[\" property3\" ]}," +
314
+ "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
308
315
"\" properties\" :{\" property1\" :{\" type\" :\" integer\" }" +
309
316
",\" property2\" :{\" type\" :\" string\" }," +
310
317
"\" property3\" :{\" type\" :\" array\" ,\" items\" :{\" type\" :\" string\" }}," +
@@ -313,7 +320,9 @@ public void testMultiplePropertyDependencies() throws Exception {
313
320
}
314
321
315
322
public void testSchemaPropertyDependency () throws Exception {
316
- JsonSchemaGenerator generator = new JsonSchemaGenerator (MAPPER );
323
+ ObjectMapper mapper = new ObjectMapper ();
324
+ mapper .configure (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true );
325
+ JsonSchemaGenerator generator = new JsonSchemaGenerator (mapper );
317
326
318
327
// Given this dependency schema
319
328
JsonSchema schemaPropertyDependency = generator .generateSchema (DependencySchema .class );
@@ -322,14 +331,14 @@ public void testSchemaPropertyDependency() throws Exception {
322
331
JsonSchema simpleBeanSchema = generator .generateSchema (SimpleBean .class );
323
332
((ObjectSchema ) simpleBeanSchema ).addSchemaDependency ("property1" , schemaPropertyDependency );
324
333
325
- Map <String , Object > result = writeAndMap (MAPPER , simpleBeanSchema );
334
+ Map <String , Object > result = writeAndMap (mapper , simpleBeanSchema );
326
335
assertNotNull (result );
327
336
328
337
// Test the generated value.
329
- String schemaString = MAPPER .writeValueAsString (simpleBeanSchema );
338
+ String schemaString = mapper .writeValueAsString (simpleBeanSchema );
330
339
assertEquals ("{\" type\" :\" object\" ," +
331
- "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
332
340
"\" dependencies\" :{\" property1\" :{\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\" ,\" properties\" :{\" property2\" :{\" type\" :\" string\" ,\" required\" :true}}}}," +
341
+ "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
333
342
"\" properties\" :{\" property1\" :{\" type\" :\" integer\" }" +
334
343
",\" property2\" :{\" type\" :\" string\" }," +
335
344
"\" property3\" :{\" type\" :\" array\" ,\" items\" :{\" type\" :\" string\" }}," +
@@ -338,7 +347,9 @@ public void testSchemaPropertyDependency() throws Exception {
338
347
}
339
348
340
349
public void testSchemaPropertyDependencies () throws Exception {
341
- JsonSchemaGenerator generator = new JsonSchemaGenerator (MAPPER );
350
+ ObjectMapper mapper = new ObjectMapper ();
351
+ mapper .configure (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true );
352
+ JsonSchemaGenerator generator = new JsonSchemaGenerator (mapper );
342
353
343
354
// Given this dependency schema
344
355
JsonSchema schemaPropertyDependency = generator .generateSchema (DependencySchema .class );
@@ -348,18 +359,18 @@ public void testSchemaPropertyDependencies() throws Exception {
348
359
((ObjectSchema ) simpleBeanSchema ).addSchemaDependency ("property1" , schemaPropertyDependency );
349
360
((ObjectSchema ) simpleBeanSchema ).addSchemaDependency ("property3" , schemaPropertyDependency );
350
361
351
- Map <String , Object > result = writeAndMap (MAPPER , simpleBeanSchema );
362
+ Map <String , Object > result = writeAndMap (mapper , simpleBeanSchema );
352
363
assertNotNull (result );
353
364
354
365
// Test the generated value.
355
- String schemaString = MAPPER .writeValueAsString (simpleBeanSchema );
366
+ String schemaString = mapper .writeValueAsString (simpleBeanSchema );
356
367
assertEquals (
357
368
"{" +
358
369
"\" type\" :\" object\" ," +
359
- "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
360
370
"\" dependencies\" :{" +
361
371
"\" property1\" :{\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\" ,\" properties\" :{\" property2\" :{\" type\" :\" string\" ,\" required\" :true}}}," +
362
372
"\" property3\" :{\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:DependencySchema\" ,\" properties\" :{\" property2\" :{\" type\" :\" string\" ,\" required\" :true}}}}," +
373
+ "\" id\" :\" urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:TestGenerateJsonSchema:SimpleBean\" ," +
363
374
"\" properties\" :{" +
364
375
"\" property1\" :{\" type\" :\" integer\" }" +
365
376
",\" property2\" :{\" type\" :\" string\" }," +
0 commit comments