Home deserialise the list of integer from json to java using Jackson Object Mapper
Reply: 1

deserialise the list of integer from json to java using Jackson Object Mapper

Sasi Kathimanda
1#
Sasi Kathimanda Published in 2018-02-14 01:07:57Z

I have my json response like below:

{"IsValid":false,"ModelErrors":null,"ValidationErrors":[10000]}

model class:

public class ShipmentResponse {
    private boolean isValid;
    private ModelErrors modelErrors;
    private List<Integer> validationErrors = null;

Object Mapper code :

ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ShipmentResponse shipmentResponse =  mapper.readValue((BufferedInputStream)response.getEntity(), ShipmentResponse.class);

i could not able to map the validationErrors from json to java ,i.e., validationErrors = null after parsing .Im expecting validationErrors = {1000} but not sure why? i know we can use TypeReference to return array or list but not nested inside data object.

Antoniossss
2#
Antoniossss Reply to 2018-02-14 01:16:23Z

Try this

    public class ShipmentResponse {

        @JsonProperty("IsValid")
        private boolean isValid;
        @JsonProperty("ModelErrors")
        private ModelErrors modelErrors;
        @JsonProperty("ValidationErrors")
        private List<Integer> validationErrors = null;
}

In general you have missmatch in your property names and actual json (case matters)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.357861 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO