Good Morning,
I'm relatively new to java and trying to to work through a project, but I'm running into issues. My program uses SQL to build a URL to call a web-service, this service will return the following JSON:
[{
"MmisItemNo": "106552",
"CatalogNo": "UM18840041R",
"ContractOn": "False"
}
]
What I need to do is strip off the "False" or "True" value at the end to do additional logic depending on its result.
I keep getting the following error:
.WebCall -com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
deserialize instance of `.LightswitchResponse` out of START_ARRAY token at [Source: (String)"[{"MmisItemNo":"106552","CatalogNo":"UM18840041R","ContractOn":"False"}]"; line: 1, column: 1]
Here is my code currently after the URL is built in the WebCall.java class:
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
ObjectMapper mapper = new ObjectMapper();
LightswitchResponse lightswitchResponse = mapper.readValue(response.toString(), LightswitchResponse.class);
System.out.println(lightswitchResponse.ContractOn);
In my second class the code is as follows:
public class LightswitchResponse {
String MmisItemNo;
String CatalogNo;
boolean ContractOn;
public String getMmisItemNo() {
return MmisItemNo;
}
public void setMmisItemNo(String mmisItemNo) {
MmisItemNo = mmisItemNo;
}
public String getCatalogNo() {
return CatalogNo;
}
public void setCatalogNo(String catalogNo) {
CatalogNo = catalogNo;
}
public boolean ContractOn() {
return ContractOn;
}
public void setContractOn(boolean contractOn) {
ContractOn = contractOn;
}
}
Any ideas on what might be going wrong? I feel like it might have something to do with the [] on the JSON response, but not 100% sure.