- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
try {
// Store settings in the database as a JSON string
machine.setSettings(CustomJacksonRepresentation.createCanonicalObjectMapper().writeValueAsString(
request.getSettings()));
} catch (final JsonMappingException e) {
// We obtained request by parsing JSON in the first place,
// no way it can fail to be serialized back o_O
throw new AssertionError(e);
} catch (final JsonGenerationException e) {
// See above
throw new AssertionError(e);
} catch (final IOException e) {
// Why does writeValueAsString throw IOException anyway? How CAN you fail to write to a String?
// Seriously, what were the writers of Jackson smoking that they exposed IOException in the API
// in a method specifically designed to serialize to String, just because the underlying implementation
// uses StringWriter (which doesn't really throw IOException anyway)?
// I mean, I understand if the string is too long to fit in memory, but that's an OutOfMemoryError
throw new AssertionError(e);
}