@JsonPropertyOrder does not work with jackson-module-jsonSchema

I use the last branch for the Jackson module - jackson-module-jsonSchema, i.e. 2.4.4-Snapshot.

I am trying to use the @JsonPropertyOrder annotation to maintain the order of the POJO attributes, but does not seem to abide by the annotation.

My POJO example is as follows:

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's code is as follows:

 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 output is as follows:

 { "type": "object", "id": "urn:jsonschema:Pojo", "properties": { "b": { "type": "string" }, "a": { "type": "string" } } } 

Can someone suggest that I am doing something wrong or we need to open the problem on Jackson, as I can see that this problem is already closed in 2.3.2 ( https://github.com/FasterXML/jackson-dataformat- xml / issues / 91 )?

+6
source share
1 answer

Using @JsonPropertyOrder (alphabetic = true) This will sort all properties in alphabetical order. Works with Jackson 1.9.13

0
source

Source: https://habr.com/ru/post/978079/


All Articles