我正在使用最新的Jackson模块分支-jackson-module-jsonSchema,即2.4.4-Snapshot。
我试图使用@JsonPropertyOrder注释来维护POJO属性的顺序,但它似乎没有遵守该注释。
我的示例POJO如下-
我试图使用@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;
}
}
Jackson代码如下 -
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"
}
}
}
有人能否建议一下,我是否做错了什么或者我们需要在jackson上开个问题,因为我发现这种问题已经在2.3.2中得到解决了(https://github.com/FasterXML/jackson-dataformat-xml/issues/91)?