Search in sources :

Example 6 with AnnotatedClass

use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project druid by druid-io.

the class IncrementalIndexCreator method getAppendableIndexTypes.

/**
 * Fetch all the available incremental-index implementations.
 * It can be used to parametrize the test. If more parameters are needed, use indexTypeCartesianProduct().
 * @see #indexTypeCartesianProduct(Collection[]).
 *
 * @return a list of all the incremental-index implementations types (String)
 */
public static List<String> getAppendableIndexTypes() {
    SubtypeResolver resolver = JSON_MAPPER.getSubtypeResolver();
    MapperConfig<?> config = JSON_MAPPER.getDeserializationConfig();
    AnnotatedClass cls = AnnotatedClassResolver.resolveWithoutSuperTypes(config, AppendableIndexSpec.class);
    Collection<NamedType> types = resolver.collectAndResolveSubtypesByClass(config, cls);
    return types.stream().map(NamedType::getName).filter(Objects::nonNull).distinct().collect(Collectors.toList());
}
Also used : SubtypeResolver(com.fasterxml.jackson.databind.jsontype.SubtypeResolver) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) Objects(java.util.Objects)

Example 7 with AnnotatedClass

use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project druid by druid-io.

the class InputSourceModuleTest method testSubTypeRegistration.

@Test
public void testSubTypeRegistration() {
    MapperConfig config = mapper.getDeserializationConfig();
    AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, SqlInputSource.class);
    List<String> subtypes = mapper.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass).stream().map(NamedType::getName).collect(Collectors.toList());
    Assert.assertNotNull(subtypes);
    Assert.assertEquals(SQL_NAMED_TYPE, Iterables.getOnlyElement(subtypes));
}
Also used : AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) MapperConfig(com.fasterxml.jackson.databind.cfg.MapperConfig) Test(org.junit.Test)

Example 8 with AnnotatedClass

use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project druid by druid-io.

the class FirehoseModuleTest method getFirehoseFactorySubtypeClasses.

private static Set<Class> getFirehoseFactorySubtypeClasses(ObjectMapper objectMapper) {
    Class parentClass = FirehoseFactory.class;
    MapperConfig config = objectMapper.getDeserializationConfig();
    AnnotatedClass ac = AnnotatedClass.constructWithoutSuperTypes(parentClass, config);
    Collection<NamedType> subtypes = objectMapper.getSubtypeResolver().collectAndResolveSubtypesByClass(config, ac);
    Assert.assertNotNull(subtypes);
    return subtypes.stream().map(NamedType::getType).filter(c -> !c.equals(parentClass)).collect(Collectors.toSet());
}
Also used : Module(com.fasterxml.jackson.databind.Module) JvmUtils(org.apache.druid.utils.JvmUtils) FirehoseFactory(org.apache.druid.data.input.FirehoseFactory) URL(java.net.URL) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) URLClassLoader(java.net.URLClassLoader) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) ClippedFirehoseFactory(org.apache.druid.segment.realtime.firehose.ClippedFirehoseFactory) Modifier(java.lang.reflect.Modifier) MapperConfig(com.fasterxml.jackson.databind.cfg.MapperConfig) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) ClassPath(com.google.common.reflect.ClassPath) Assert(org.junit.Assert) FirehoseFactory(org.apache.druid.data.input.FirehoseFactory) ClippedFirehoseFactory(org.apache.druid.segment.realtime.firehose.ClippedFirehoseFactory) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) MapperConfig(com.fasterxml.jackson.databind.cfg.MapperConfig) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass)

Example 9 with AnnotatedClass

use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project jackson-databind by FasterXML.

the class TestAnnotatedClass method testFieldIntrospection.

public void testFieldIntrospection() {
    SerializationConfig config = MAPPER.getSerializationConfig();
    JavaType t = MAPPER.constructType(FieldBean.class);
    AnnotatedClass ac = AnnotatedClass.construct(t, config);
    // AnnotatedClass does not ignore non-visible fields, yet
    assertEquals(2, ac.getFieldCount());
    for (AnnotatedField f : ac.fields()) {
        String fname = f.getName();
        if (!"bar".equals(fname) && !"props".equals(fname)) {
            fail("Unexpected field name '" + fname + "'");
        }
    }
}
Also used : AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) AnnotatedField(com.fasterxml.jackson.databind.introspect.AnnotatedField)

Example 10 with AnnotatedClass

use of com.fasterxml.jackson.databind.introspect.AnnotatedClass in project jackson-databind by FasterXML.

the class TestAnnotatedClass method testConstructorIntrospection.

// For [databind#1005]
public void testConstructorIntrospection() {
    // Need this call to ensure there is a synthetic constructor being generated
    // (not really needed otherwise)
    Bean1005 bean = new Bean1005(13);
    SerializationConfig config = MAPPER.getSerializationConfig();
    JavaType t = MAPPER.constructType(bean.getClass());
    AnnotatedClass ac = AnnotatedClass.construct(t, config);
    assertEquals(1, ac.getConstructors().size());
}
Also used : AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass)

Aggregations

AnnotatedClass (com.fasterxml.jackson.databind.introspect.AnnotatedClass)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 AnnotatedField (com.fasterxml.jackson.databind.introspect.AnnotatedField)3 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)3 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)2 MapperConfig (com.fasterxml.jackson.databind.cfg.MapperConfig)2 AnnotationMap (com.fasterxml.jackson.databind.introspect.AnnotationMap)2 JacksonAnnotationIntrospector (com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 Test (org.junit.Test)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)1 Module (com.fasterxml.jackson.databind.Module)1 Annotated (com.fasterxml.jackson.databind.introspect.Annotated)1 AnnotatedParameter (com.fasterxml.jackson.databind.introspect.AnnotatedParameter)1 SubtypeResolver (com.fasterxml.jackson.databind.jsontype.SubtypeResolver)1 ClassKey (com.fasterxml.jackson.databind.type.ClassKey)1 ResourceTransformer (com.google.api.server.spi.config.ResourceTransformer)1 Transformer (com.google.api.server.spi.config.Transformer)1 ClassPath (com.google.common.reflect.ClassPath)1 IOException (java.io.IOException)1