Skip to content

Commit

Permalink
https://github.com/FasterXML/jackson-module-jsonSchema/issues/27
Browse files Browse the repository at this point in the history
  • Loading branch information
idelvall committed Sep 1, 2015
1 parent 163f7db commit f82823e
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.fasterxml.jackson.module.jsonSchema;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.MapperFeature;

import com.fasterxml.jackson.databind.ObjectMapper;

public class TestPropertyOrderInSchema extends SchemaTestBase {

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

private int b;
Expand Down Expand Up @@ -37,18 +38,59 @@ public void setA(String a) {
this.a = a;
}
}

@JsonPropertyOrder(alphabetic = true)
static class Bean2 {

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 {
public void testAnnotationOrder() throws Exception {
ObjectMapper MAPPER = objectMapper();
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER);
JsonSchema jsonSchema = generator.generateSchema(Bean.class);
System.out.println(jsonSchema.asObjectSchema().getProperties().keySet());
assertEquals(jsonSchema.asObjectSchema().getProperties().keySet().toString(), "[c, b, a]");
}

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

Expand Down

0 comments on commit f82823e

Please sign in to comment.