Skip to content

Commit f82823e

Browse files
committed
https://github.com/FasterXML/jackson-module-jsonSchema/issues/27
1 parent 163f7db commit f82823e

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/test/java/com/fasterxml/jackson/module/jsonSchema/TestPropertyOrderInSchema.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.fasterxml.jackson.module.jsonSchema;
22

33
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
import com.fasterxml.jackson.databind.MapperFeature;
45

56
import com.fasterxml.jackson.databind.ObjectMapper;
67

78
public class TestPropertyOrderInSchema extends SchemaTestBase {
89

9-
@JsonPropertyOrder({"a", "b", "c"})
10+
@JsonPropertyOrder({"c", "b", "a"})
1011
static class Bean {
1112

1213
private int b;
@@ -37,18 +38,59 @@ public void setA(String a) {
3738
this.a = a;
3839
}
3940
}
41+
42+
@JsonPropertyOrder(alphabetic = true)
43+
static class Bean2 {
44+
45+
private int b;
46+
private String c;
47+
private String a;
48+
49+
public int getB() {
50+
return b;
51+
}
52+
53+
public void setB(int b) {
54+
this.b = b;
55+
}
56+
57+
public String getC() {
58+
return c;
59+
}
60+
61+
public void setC(String c) {
62+
this.c = c;
63+
}
64+
65+
public String getA() {
66+
return a;
67+
}
68+
69+
public void setA(String a) {
70+
this.a = a;
71+
}
72+
}
4073

4174
/*
4275
/**********************************************************
4376
/* Unit tests
4477
/**********************************************************
4578
*/
46-
final ObjectMapper MAPPER = objectMapper();
79+
4780

48-
public void testCorrectOrder() throws Exception {
81+
public void testAnnotationOrder() throws Exception {
82+
ObjectMapper MAPPER = objectMapper();
4983
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
5084
JsonSchema jsonSchema = generator.generateSchema(Bean.class);
5185
System.out.println(jsonSchema.asObjectSchema().getProperties().keySet());
86+
assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[c, b, a]");
87+
}
88+
89+
public void testAlphabeticOrder() throws Exception {
90+
final ObjectMapper MAPPER = objectMapper();
91+
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
92+
JsonSchema jsonSchema = generator.generateSchema(Bean2.class);
93+
System.out.println(jsonSchema.asObjectSchema().getProperties().keySet());
5294
assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[a, b, c]");
5395
}
5496

0 commit comments

Comments
 (0)