use of io.atomix.utils.config.ConfigurationException in project atomix by atomix.
the class PolymorphicTypeDeserializer method deserialize.
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
ObjectMapper mapper = (ObjectMapper) p.getCodec();
ObjectNode root = mapper.readTree(p);
Iterator<Map.Entry<String, JsonNode>> iterator = root.fields();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> entry = iterator.next();
if (entry.getKey().equals(TYPE_KEY)) {
Class<? extends T> configClass = concreteFactory.apply(entry.getValue().asText());
root.remove(TYPE_KEY);
return mapper.convertValue(root, configClass);
}
}
throw new ConfigurationException("Failed to deserialize polymorphic " + _valueClass.getSimpleName() + " configuration");
}
Aggregations