Om Komawar
Om Komawar

Reputation: 251

How to deserialize JSON response using @JsonProperty?

I have this object which is converted into following format but it does not wrap it properly.

@JsonProperty("code")
private String code;
@JsonProperty("message")
private String msg;
@JsonProperty("assign")
private SomeVO someVO;
//getter, setters

to this format:

{
"status": {
     "code": $value, 
     "message": $value
},
"data":{
   "assign" {
    "schemaLayoutFileName" : $value
    "dataStoreTargetLocationText" : $value
       }
   }

}

How can it be done?

Upvotes: 0

Views: 634

Answers (1)

cassiomolin
cassiomolin

Reputation: 130967

The class you have defined does not match the JSON you want to parse. Try the following design (if the class attributes names match the JSON properties names, you won't need @JsonProperty):

public class Foo {

    private Status status;
    private Data data;

    // Getters and setters
}
public class Status {

    private String code;
    private String value;

    // Getters and setters
}
public class Data {

    private Assign assign;

    // Getters and setters
}
public class Assign {

    private String schemaLayoutFileName;
    private String dataStoreTargetLocationText;

    // Getters and setters
}

Upvotes: 2

Related Questions