Search in sources :

Example 16 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project druid by druid-io.

the class HdfsDataSegmentFinderTest method setupStatic.

@BeforeClass
public static void setupStatic() throws IOException {
    mapper.registerSubtypes(new NamedType(NumberedShardSpec.class, "numbered"));
    hdfsTmpDir = File.createTempFile("hdfsDataSource", "dir");
    if (!hdfsTmpDir.delete()) {
        throw new IOException(String.format("Unable to delete hdfsTmpDir [%s]", hdfsTmpDir.getAbsolutePath()));
    }
    conf = new Configuration(true);
    conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsTmpDir.getAbsolutePath());
    miniCluster = new MiniDFSCluster.Builder(conf).build();
    uriBase = miniCluster.getURI();
    fs = miniCluster.getFileSystem();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) IOException(java.io.IOException) NumberedShardSpec(io.druid.timeline.partition.NumberedShardSpec) BeforeClass(org.junit.BeforeClass)

Example 17 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class StdSubtypeResolver method registerSubtypes.

@Override
public void registerSubtypes(Class<?>... classes) {
    NamedType[] types = new NamedType[classes.length];
    for (int i = 0, len = classes.length; i < len; ++i) {
        types[i] = new NamedType(classes[i]);
    }
    registerSubtypes(types);
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType)

Example 18 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class StdSubtypeResolver method collectAndResolveSubtypesByClass.

/*
    /**********************************************************
    /* Resolution by class (serialization)
    /**********************************************************
     */
@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedMember property, JavaType baseType) {
    final AnnotationIntrospector ai = config.getAnnotationIntrospector();
    // for backwards compatibility, must allow null here:
    Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
    HashMap<NamedType, NamedType> collected = new HashMap<NamedType, NamedType>();
    // start with registered subtypes (which have precedence)
    if (_registeredSubtypes != null) {
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) {
                // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
                _collectAndResolve(curr, subtype, config, ai, collected);
            }
        }
    }
    // then annotated types for property itself
    Collection<NamedType> st = ai.findSubtypes(property);
    if (st != null) {
        for (NamedType nt : st) {
            AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(nt.getType(), config);
            _collectAndResolve(ac, nt, config, ai, collected);
        }
    }
    NamedType rootType = new NamedType(rawBase, null);
    AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(rawBase, config);
    // and finally subtypes via annotations from base type (recursively)
    _collectAndResolve(ac, rootType, config, ai, collected);
    return new ArrayList<NamedType>(collected.values());
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Example 19 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class StdSubtypeResolver method collectAndResolveSubtypesByTypeId.

@Override
public Collection<NamedType> collectAndResolveSubtypesByTypeId(MapperConfig<?> config, AnnotatedClass type) {
    Set<Class<?>> typesHandled = new HashSet<Class<?>>();
    Map<String, NamedType> byName = new LinkedHashMap<String, NamedType>();
    NamedType rootType = new NamedType(type.getRawType(), null);
    _collectAndResolveByTypeId(type, rootType, config, typesHandled, byName);
    if (_registeredSubtypes != null) {
        Class<?> rawBase = type.getRawType();
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) {
                // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
                _collectAndResolveByTypeId(curr, subtype, config, typesHandled, byName);
            }
        }
    }
    return _combineNamedAndUnnamed(typesHandled, byName);
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType)

Example 20 with NamedType

use of com.fasterxml.jackson.databind.jsontype.NamedType in project jackson-databind by FasterXML.

the class StdSubtypeResolver method collectAndResolveSubtypesByClass.

@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config, AnnotatedClass type) {
    final AnnotationIntrospector ai = config.getAnnotationIntrospector();
    HashMap<NamedType, NamedType> subtypes = new HashMap<NamedType, NamedType>();
    // then consider registered subtypes (which have precedence over annotations)
    if (_registeredSubtypes != null) {
        Class<?> rawBase = type.getRawType();
        for (NamedType subtype : _registeredSubtypes) {
            // is it a subtype of root type?
            if (rawBase.isAssignableFrom(subtype.getType())) {
                // yes
                AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
                _collectAndResolve(curr, subtype, config, ai, subtypes);
            }
        }
    }
    // and then check subtypes via annotations from base type (recursively)
    NamedType rootType = new NamedType(type.getRawType(), null);
    _collectAndResolve(type, rootType, config, ai, subtypes);
    return new ArrayList<NamedType>(subtypes.values());
}
Also used : NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector)

Aggregations

NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)27 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ApiModel (io.swagger.annotations.ApiModel)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 TypeSerializer (com.fasterxml.jackson.databind.jsontype.TypeSerializer)2 DataSchema (io.druid.segment.indexing.DataSchema)2 UniformGranularitySpec (io.druid.segment.indexing.granularity.UniformGranularitySpec)2 HashBasedNumberedShardSpec (io.druid.timeline.partition.HashBasedNumberedShardSpec)2 ApiModelProperty (io.swagger.annotations.ApiModelProperty)2 ComposedModel (io.swagger.models.ComposedModel)2 Model (io.swagger.models.Model)2 ModelImpl (io.swagger.models.ModelImpl)2 RefModel (io.swagger.models.RefModel)2 AbstractNumericProperty (io.swagger.models.properties.AbstractNumericProperty)2 ArrayProperty (io.swagger.models.properties.ArrayProperty)2