Piy*_*joo 6 java json jsonschema jackson jackson-modules
我正在使用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;
}
}
Run Code Online (Sandbox Code Playgroud)
杰克逊代码如下 -
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));
}
}
Run Code Online (Sandbox Code Playgroud)
Json输出如下 -
{
"type": "object",
"id": "urn:jsonschema:Pojo",
"properties": {
"b": {
"type": "string"
},
"a": {
"type": "string"
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可能会建议我做错了什么或者我们是否需要在杰克逊面前打开一个问题,因为我看到这个问题已经在2.3.2中关闭了(https://github.com/FasterXML/jackson- dataformat-xml/issues/91)?
| 归档时间: |
|
| 查看次数: |
2494 次 |
| 最近记录: |