I'm using Gson to (de)serialize between Json string and Java Object, it's convenient but, when the string contains some invalid value, gson only returns exception and states the type of exception.
For example, I have some class like :
public class Employee {
public String name;
public Integer age;
}
If I try to deserialize like this :
try {
String data = "{\"name\":\"Alan\",\"age\":\"twenty-eight\"}";
Employee employee = gson.fromJson(data, Employee.class);
} catch (Exception e) {
logger.warn(e);
}
It outputs
java.lang.NumberFormatException: For input string: "a"
Is there any method to know the invalid field("age" in this case) as well? I've referenced question, but it seems not suitable in this case.