Skip to content

Commit

Permalink
object schema property order
Browse files Browse the repository at this point in the history
  • Loading branch information
idelvall committed Sep 1, 2015
1 parent 22098c5 commit 58c9737
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fasterxml.jackson.module.jsonSchema.types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -12,6 +11,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import java.util.LinkedHashMap;

/**
* This type represents a {@link JsonSchema} as an object type
Expand Down Expand Up @@ -68,8 +68,8 @@ public class ObjectSchema extends ContainerTypeSchema
public ObjectSchema()
{
dependencies = new ArrayList<Dependency>();
patternProperties = new HashMap<String, JsonSchema>();
properties = new HashMap<String, JsonSchema>();
patternProperties = new LinkedHashMap<String, JsonSchema>();
properties = new LinkedHashMap<String, JsonSchema>();
}

public boolean addSchemaDependency(String depender, JsonSchema parentMustMatch) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.fasterxml.jackson.module.jsonSchema;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import com.fasterxml.jackson.databind.ObjectMapper;

public class TestPropertyOrderInSchema extends SchemaTestBase {

@JsonPropertyOrder({"a", "b", "c"})
static class Bean {

private int b;
private String c;
private String a;

public int getB() {
return b;
}

public void setB(int b) {
this.b = b;
}

public String getC() {
return c;
}

public void setC(String c) {
this.c = c;
}

public String getA() {
return a;
}

public void setA(String a) {
this.a = a;
}
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
final ObjectMapper MAPPER = objectMapper();

public void testCorrectOrder() throws Exception {
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
JsonSchema jsonSchema = generator.generateSchema(Bean.class);
System.out.println(jsonSchema.asObjectSchema().getProperties().keySet());
assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[a, b, c]");
}

}

0 comments on commit 58c9737

Please sign in to comment.