I have a JSON value as follows in String format.
{
"Sample": {
"name": "some name",
"key": "some key"
},
"Offering": {
"offer": "some offer",
"amount": 100
}
}
Now if I try to map this as follows, it works and maps fine.
//mapper is ObjectMapper;
//data is the above json in String format
Map vo = mapper.readValue(data, Map.class);
But I want to map it to a custom Data class as follows.
Data vo = mapper.readValue(data, Data.class);
When I do this, the result of vo is null.
Refer to following on how the Data class is structured.
@Getter
@Setter
public class Data {
private Sample sample;
private Offering offering;
}
@Getter
@Setter
public class Offering {
public String offer;
public int amount;
}
@Getter
@Setter
public class Sample {
private String name;
private String key;
}
Please advice what I am doing wrong. Thanks.