Skip to content

Commit 58c9737

Browse files
committed
object schema property order
FasterXML#27
1 parent 22098c5 commit 58c9737

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/main/java/com/fasterxml/jackson/module/jsonSchema/types/ObjectSchema.java

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

33
import java.util.ArrayList;
4-
import java.util.HashMap;
54
import java.util.List;
65
import java.util.Map;
76

@@ -12,6 +11,7 @@
1211
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1312
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
1413
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
14+
import java.util.LinkedHashMap;
1515

1616
/**
1717
* This type represents a {@link JsonSchema} as an object type
@@ -68,8 +68,8 @@ public class ObjectSchema extends ContainerTypeSchema
6868
public ObjectSchema()
6969
{
7070
dependencies = new ArrayList<Dependency>();
71-
patternProperties = new HashMap<String, JsonSchema>();
72-
properties = new HashMap<String, JsonSchema>();
71+
patternProperties = new LinkedHashMap<String, JsonSchema>();
72+
properties = new LinkedHashMap<String, JsonSchema>();
7373
}
7474

7575
public boolean addSchemaDependency(String depender, JsonSchema parentMustMatch) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fasterxml.jackson.module.jsonSchema;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
7+
public class TestPropertyOrderInSchema extends SchemaTestBase {
8+
9+
@JsonPropertyOrder({"a", "b", "c"})
10+
static class Bean {
11+
12+
private int b;
13+
private String c;
14+
private String a;
15+
16+
public int getB() {
17+
return b;
18+
}
19+
20+
public void setB(int b) {
21+
this.b = b;
22+
}
23+
24+
public String getC() {
25+
return c;
26+
}
27+
28+
public void setC(String c) {
29+
this.c = c;
30+
}
31+
32+
public String getA() {
33+
return a;
34+
}
35+
36+
public void setA(String a) {
37+
this.a = a;
38+
}
39+
}
40+
41+
/*
42+
/**********************************************************
43+
/* Unit tests
44+
/**********************************************************
45+
*/
46+
final ObjectMapper MAPPER = objectMapper();
47+
48+
public void testCorrectOrder() throws Exception {
49+
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
50+
JsonSchema jsonSchema = generator.generateSchema(Bean.class);
51+
System.out.println(jsonSchema.asObjectSchema().getProperties().keySet());
52+
assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[a, b, c]");
53+
}
54+
55+
}

0 commit comments

Comments
 (0)