close

[Solved] Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Cannot deserialize instance of java.lang.String out of START_OBJECT token in java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Cannot deserialize instance of java.lang.String out of START_OBJECT token Error Occurs?

Today I get the following error Cannot deserialize instance of java.lang.String out of START_OBJECT token in java.

How To Solve Cannot deserialize instance of java.lang.String out of START_OBJECT token Error ?

  1. How To Solve Cannot deserialize instance of java.lang.String out of START_OBJECT token Error ?

    To Solve Cannot deserialize instance of java.lang.String out of START_OBJECT token Error Data content is so variable, I think the best form is to define it as “ObjectNode” and next create his own class to parse:

  2. Cannot deserialize instance of java.lang.String out of START_OBJECT token

    To Solve Cannot deserialize instance of java.lang.String out of START_OBJECT token Error Data content is so variable, I think the best form is to define it as “ObjectNode” and next create his own class to parse:

Solution 1

You’re mapping this JSON

{
    "id": 2,
    "socket": "0c317829-69bf-43d6-b598-7c0c550635bb",
    "type": "getDashboard",
    "data": {
        "workstationUuid": "ddec1caa-a97f-4922-833f-632da07ffc11"
    },
    "reply": true
}

that contains an element named data that has a JSON object as its value. You are trying to deserialize the element named workstationUuid from that JSON object into this setter.

@JsonProperty("workstationUuid")
public void setWorkstation(String workstationUUID) {

This won’t work directly because Jackson sees a JSON_OBJECT, not a String.

Try creating a class Data

public class Data { // the name doesn't matter 
    @JsonProperty("workstationUuid")
    private String workstationUuid;
    // getter and setter
}

the switch up your method

@JsonProperty("data")
public void setWorkstation(Data data) {
    // use getter to retrieve it

Solution 2

Data content is so variable, I think the best form is to define it as “ObjectNode” and next create his own class to parse:

Finally:

private ObjectNode data;

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment