I have a rest endpoint with the following response
{
"Shops": {
"Shop": [
{
"RowID": "1",
"Penalties": {
"Penalty": [
{
"PenaltyCode": "abc-01",
"PenaltyCount": "1"
},
{
"PenaltyCode": "abc-02",
"PenaltyCount": "2"
}
]
},
"VisitOutComes": {
"VisitOutCome": {
"TaskOutComeName": "text",
"TaskOutComeCount": "1"
}
}
}
]
}
}
I need to insert the response in a RDMS using hibernate. I already done the hibernate part and the rest client part. I am confused how to map the json to java classes.
I write the follwing classes , getter and setter are omitted for clarity.
public class Shops {
@JsonProperty("Shop")
private ArrayList<Shop> shop ;
public class Shop {
@JsonProperty("VisitOutComes")
private VisitOutComes visitOutComes ;
@JsonProperty("Penalties")
private Penalties penalties ;
@JsonProperty("RowID")
private String rowID ;
public class VisitOutComes {
@JsonProperty("VisitOutCome")
ArrayList<VisitOutCome> visitOutCome ;
public class Penalties {
@JsonProperty("Penalty")
ArrayList<Penalty> penalty ;
public class VisitOutCome {
@JsonProperty("TaskOutComeCount")
private String TaskOutComeCount;
@JsonProperty("TaskOutComeName")
private String TaskOutComeName ;
public class Penalty {
@JsonProperty("penaltyCode")
private String penaltyCode ;
@JsonProperty("penaltyCount")
private String penaltyCount ;
Then I wirte the main method as follows :
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
String path = "C:\\jars\\response.json" ;
Shops shops = mapper.readValue(new File(path),Shops.class);
Finally I get the error
Cannot deserialize instance of java.util.ArrayList jscksondemo.VisitOutCome out of START_OBJECT token
I appreciate any help on how to create the maping for this json file.