Created
January 20, 2020 16:47
-
-
Save purplefox/8975123fcc97da9c7f00eb2ce5ccf8ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> T deserialiseObject(final Buffer buffer, final HttpServerResponse response, | |
final Class<T> clazz) { | |
final ObjectMapper objectMapper = DatabindCodec.mapper(); | |
try { | |
final T t = objectMapper.readValue(buffer.getBytes(), clazz); | |
} catch (UnrecognizedPropertyException e) { | |
sendUnrecognisedPropertyError(e.getPropertyName(), response); | |
return null; | |
} catch (MismatchedInputException e) { | |
final int startIndex = e.getMessage().indexOf('\''); | |
final int endIndex = e.getMessage().indexOf('\'', startIndex + 1); | |
final String propertyName = e.getMessage().substring(startIndex + 1, endIndex); | |
sendMissingPropertyError(propertyName, response); | |
return null; | |
} catch (JsonParseException e) { | |
sendInvalidJsonError(response); | |
return null; | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment