|
1 | 1 | package com.fasterxml.jackson.module.jsonSchema;
|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
| 4 | +import com.fasterxml.jackson.databind.MapperFeature; |
4 | 5 |
|
5 | 6 | import com.fasterxml.jackson.databind.ObjectMapper;
|
6 | 7 |
|
7 | 8 | public class TestPropertyOrderInSchema extends SchemaTestBase {
|
8 | 9 |
|
9 |
| - @JsonPropertyOrder({"a", "b", "c"}) |
| 10 | + @JsonPropertyOrder({"c", "b", "a"}) |
10 | 11 | static class Bean {
|
11 | 12 |
|
12 | 13 | private int b;
|
@@ -37,18 +38,59 @@ public void setA(String a) {
|
37 | 38 | this.a = a;
|
38 | 39 | }
|
39 | 40 | }
|
| 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 | + } |
40 | 73 |
|
41 | 74 | /*
|
42 | 75 | /**********************************************************
|
43 | 76 | /* Unit tests
|
44 | 77 | /**********************************************************
|
45 | 78 | */
|
46 |
| - final ObjectMapper MAPPER = objectMapper(); |
| 79 | + |
47 | 80 |
|
48 |
| - public void testCorrectOrder() throws Exception { |
| 81 | + public void testAnnotationOrder() throws Exception { |
| 82 | + ObjectMapper MAPPER = objectMapper(); |
49 | 83 | JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
|
50 | 84 | JsonSchema jsonSchema = generator.generateSchema(Bean.class);
|
51 | 85 | 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()); |
52 | 94 | assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[a, b, c]");
|
53 | 95 | }
|
54 | 96 |
|
|
0 commit comments