@Override
public Record deserialize(final JsonParser jsonParser,
final DeserializationContext ctxt) throws JsonProcessingException,
IOException {
final ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
final ObjectReader reader = mapper.reader().without(
DeserializationFeature.UNWRAP_ROOT_VALUE);
final ObjectNode recordNode = reader.readTree(jsonParser);
final JsonNode recordTypeNode = recordNode.get(TYPE_FIELD_NAME);
if (recordTypeNode == null) {
throw new JsonDeserializationException(
JsonDeserializationExceptionCode.missingField,
TYPE_FIELD_NAME, "resource record");
}
final String recordType = recordTypeNode.textValue();
final Class<? extends Record> recordClass = recordClassesRegistry
.get(recordType);
if (recordClass == null) {
throw new JsonDeserializationException(
JsonDeserializationExceptionCode.unknownResourceRecordType,
recordType);
}
return reader.withType(recordClass).readValue(recordNode.toString());
}