Jackson モジュールの最新のブランチ (jackson-module-jsonSchema、つまり 2.4.4-Snapshot) を使用しています。
@JsonPropertyOrder アノテーションを使用して POJO 属性の順序を維持しようとしていますが、アノテーションを尊重していないようです。
私のサンプルPOJOは次のとおりです-
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@JsonPropertyOrder({"a", "b"})
class Pojo {
private String a;
private String b;
public Pojo(final String a, final String b) {
this.a = a;
this.b = b;
}
public void setA(final String a) {
this.a = a;
}
public void setB(final String b) {
this.b = b;
}
public String getA() {
return this.a;
}
public String getB() {
return this.b;
}
}
ジャクソンコードは次のとおりです-
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
public class Test {
public static void main(String[] args) throws JsonProcessingException {
// TODO Auto-generated method stub
final ObjectMapper mapper = new ObjectMapper();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(mapper.constructType(Pojo.class), visitor);
final JsonSchema jsonSchema = visitor.finalSchema();
System.out.println(mapper.writeValueAsString(jsonSchema));
}
}
Json出力は次のとおりです-
{
"type": "object",
"id": "urn:jsonschema:Pojo",
"properties": {
"b": {
"type": "string"
},
"a": {
"type": "string"
}
}
}
この種の問題は2.3.2ですでにクローズされていることがわかっているので、誰かが私が何か間違ったことをしているのか、それともジャクソンで問題を開く必要があるのか を提案できますか ( https://github.com/FasterXML/jackson- dataformat-xml/issues/91 )?