Below is the json response i am converting to pojo using jackson -
{
paymentType": [
{
"Monthly": ["Monthly", "Monthly"],
"Prepaid": ["Prepaid", "Prepaid"]
},
""
]
}
Code:
String rspString = "{\"paymentType\": [{\"Monthly\": [\"Monthly\",\"Monthly\"],\"Prepaid\": [\"Prepaid\",\"Prepaid\"]},\"\"]}";
JsonUtil jsonUtil = new JsonUtil();
PaymentTypeResponse PaymentTypeRsp = new PaymentTypeResponse();
PaymentTypeRsp = (PaymentTypeResponse) jsonUtil.Json2Object(rspString, PaymentTypeRsp);
System.out.println(PaymentTypeRsp.getPaymentType().size());
I am getting the below exception:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.test.sample.PaymentTypeRespons] from String value (''); no single-String constructor/factory method
There is a blank value in the response, how to handle those values while converting to pojo?
In the same way if null is there how to handle this case?
Any pointer would be appreciated.
Thanks in advance.
Here is the class:
public class PaymentType
{
@JsonProperty("Monthly")
public List<String> monthly;
@JsonProperty("Prepaid")
public List<String> prepaid;
//getter and setters
}
public PaymentTypeResponse
{
@JsonProperty("paymentType")
public List<PaymentType> paymentType;
//setters and Getters
}