I have a JSON schema and a json string that matches the schema, except that it can contain a few extra fields. Jackson throws an exception if these fields exist, if I do not add objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); . Is there a way to get a collection of these extra fields to register them even if I throw an exception?
Here is the corresponding bit of code:
public boolean validate(Message<String> json) { List<String> errorList = jsonSchema.validate(json.getPayload()); ObjectMapper mapper = new ObjectMapper(); try { Update update = mapper.readValue(json.getPayload(), Update.class); } catch (IOException e) { System.out.println("Broken"); } if(!errorList.isEmpty()) { LOG.warn("Json message did not match schema: {}", errorList); } return true; }
source share