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();
}
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);
}
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());
}
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);
}
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());
}
Aggregations