Can not deserialize instance of java.lang.String out of START_OBJECT token

前端 未结 5 727
野的像风
野的像风 2020-12-08 12:42

I\'m running into an issue where my deployable jar hits an exception that doesn\'t happen when I run this locally in IntelliJ.

Exception:

5条回答
  •  被撕碎了的回忆
    2020-12-08 13:11

    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
    

提交回复
热议问题