更新时间:2022-02-13 22:44:48
我找到了一个使用以下线程作为参考的解决方案:
Jackson:忽略属性而不是抛出JsonMappingException
I found a solution using the following thread as reference: Jackson: ignoring properties instead of throwing JsonMappingException
我写了一个自定义反序列化器并用它来忽略错误。
I wrote a custom deserializer and used it to ignore errors.
public class CustomListingDeserializer extends JsonDeserializer<Map<String, Listing>>{
public CustomListingDeserializer() {
// TODO Auto-generated constructor stub
}
@Override
public Map<String, Listing> deserialize(JsonParser arg0, DeserializationContext arg1)
throws IOException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = arg0.readValueAsTree();
try
{
return mapper.readValue(node.toString(), new TypeReference<Map<String,Listing>>(){});
}
catch (JsonMappingException e)
{
System.out.println("Issue in deserializing : " + e.getMessage() + "for :" + node.toString());
}
catch (Exception e)
{
throw e;
}
// TODO Auto-generated method stub
return null;
}
}