json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.94k stars 1.65k forks source link

annoation support ? #556

Open fufufufuli opened 5 years ago

fufufufuli commented 5 years ago

Does this library support annoation ? such as: public class Student{ @JsonProperty("math_score") private Integer mathScore; @JsonProperty("history_score") private Integer historyScore; @JsonProperty("biological_score") private Integer biologicalScore; } String str="{\"xxx\":{\"math_score\":80,\"history_score\":85,\"biological_score\":75}}"; ReadContext readContext= JsonPath.parse(str); Student student = readContext.readContext.read("$.xxx", Student.class);

Alanscut commented 4 years ago

@fufufufuli , it support Jackson annotation by registering a JacksonmappingProvider:

    public static final Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration
            .builder()
            .mappingProvider(new JacksonMappingProvider())
            .jsonProvider(new JacksonJsonNodeJsonProvider())
            .build();
    String str="{\"xxx\":{\"math_score\":80,\"history_score\":85,\"biological_score\":75}}";
    Student student = using(JACKSON_CONFIGURATION).parse(str).read("$.xxx", Student.class);