Home > Blockchain >  How to deserialize the String which is array of objects to a array of objects?
How to deserialize the String which is array of objects to a array of objects?

Time:01-24

I have a response Body

[{"vendorName":"ABC","vendorAPI":"Some_API","enrichmentGroupingLevel":[{"Test":{"score":0.233,"risckscore":229},"level":"all"}],"error":{},"statusCode":200}]",
CoreV2Response[] getEnrichmentResponse = objectMapper.readValue(responseBody, CoreV2Response[].class);

The below is my coreV2Response class which i want to map with

public class CoreV2Response {
            @JsonProperty("vendorName")
            private String vendorName;
            @JsonProperty("vendorAPI")
            private String vendorAPI;
            @JsonProperty("enrichmentGroupingLevel")
            private Object[] enrichmentGroupingLevel;
            @JsonProperty("error")
            private Object[] error;
            @JsonProperty("statusCode")
            private int statusCode;
        }
I am getting error 
Cannot deserialize instance of [Ljava.lang.Object; out of START_OBJECT tokenat [Source: (String)"[{"vendorName":"Ekata","vendorAPI":"Account_Opening_V1.0","enrichmentGroupingLevel
```
 
Can someone help me with deserialization?
I have added my both the codes for response template class and mapper object

CodePudding user response:

In your json string error is in object

"error": {}

But in CoreV2Response you have declared the error field as object array:

private Object[] error;

You cannot deserialize json object into collection, array in your case. You have to declare error as an object

private Object error;

And deserialization goes without problems.

  •  Tags:  
  • Related