Search in sources :

Example 11 with ConfigurationException

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");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConfigurationException(io.atomix.utils.config.ConfigurationException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ConfigurationException (io.atomix.utils.config.ConfigurationException)11 Collection (java.util.Collection)5 Collectors (java.util.stream.Collectors)5 PrimitiveType (io.atomix.primitive.PrimitiveType)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)3 PartitionService (io.atomix.primitive.partition.PartitionService)3 List (java.util.List)3 Set (java.util.Set)3 Joiner (com.google.common.base.Joiner)2 Config (com.typesafe.config.Config)2 AtomixRegistry (io.atomix.core.AtomixRegistry)2 PartitionGroupMembership (io.atomix.primitive.partition.PartitionGroupMembership)2 PartitionGroupMembershipEvent (io.atomix.primitive.partition.PartitionGroupMembershipEvent)2 PrimitiveProtocol (io.atomix.primitive.protocol.PrimitiveProtocol)2 ConfigMapper (io.atomix.utils.config.ConfigMapper)2 TypedConfig (io.atomix.utils.config.TypedConfig)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Map (java.util.Map)2