[英]Continue processing when an Exception occurs
I have the below code that basically reads a bunch of JSON strings, and converts them to a java object. 我有以下代码,该代码基本上读取一堆JSON字符串,并将其转换为Java对象。 My problem is if at any point, the transformation fails for any of the JSON strings, it doesn't process the others strings. 我的问题是,在任何时候,任何JSON字符串转换都失败,它不处理其他字符串。 What I need is - 我需要的是-
Here is my code to convert from JSON to Java. 这是我的从JSON转换为Java的代码。
public static <T> T convertToObject(String jsonString,Class<T> classType){
T obj = null;
try {
obj = objectMapper.readValue(jsonString, classType);
} catch (Exception e) {
throw new Exception("Unable to convert to DTO :" + e.getMessage(), e);
}
return obj;
}
I think you need a custom deserializer. 我认为您需要自定义解串器。 Standard ObjectMapper will do all or nothing. 标准ObjectMapper将全部或不执行任何操作。 Read more about creating a custom deserializer for Jackson ObjectMapper here: 在这里阅读更多关于为Jackson ObjectMapper创建自定义解串器的信息:
http://www.baeldung.com/jackson-deserialization http://www.baeldung.com/jackson-deserialization
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.