Search in sources :

Example 11 with AnnotatedClass

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

the class RootNameLookup method findRootName.

public PropertyName findRootName(Class<?> rootType, MapperConfig<?> config) {
    ClassKey key = new ClassKey(rootType);
    PropertyName name = _rootNames.get(key);
    if (name != null) {
        return name;
    }
    BeanDescription beanDesc = config.introspectClassAnnotations(rootType);
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    AnnotatedClass ac = beanDesc.getClassInfo();
    name = intr.findRootName(ac);
    // No answer so far? Let's just default to using simple class name
    if (name == null || !name.hasSimpleName()) {
        // Should we strip out enclosing class tho? For now, nope:
        name = PropertyName.construct(rootType.getSimpleName());
    }
    _rootNames.put(key, name);
    return name;
}
Also used : AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) ClassKey(com.fasterxml.jackson.databind.type.ClassKey)

Example 12 with AnnotatedClass

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

the class JacksonResourceFieldInformationProvider method getName.

protected Optional<String> getName(Method method) {
    ObjectMapper objectMapper = context.getObjectMapper();
    SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
    if (serializationConfig != null && serializationConfig.getPropertyNamingStrategy() != null) {
        String name = ClassUtils.getGetterFieldName(method);
        Annotation[] declaredAnnotations = method.getDeclaredAnnotations();
        AnnotationMap annotationMap = buildAnnotationMap(declaredAnnotations);
        int paramsLength = method.getParameterAnnotations().length;
        AnnotationMap[] paramAnnotations = new AnnotationMap[paramsLength];
        for (int i = 0; i < paramsLength; i++) {
            AnnotationMap parameterAnnotationMap = buildAnnotationMap(method.getParameterAnnotations()[i]);
            paramAnnotations[i] = parameterAnnotationMap;
        }
        AnnotatedClass annotatedClass = AnnotatedClassBuilder.build(method.getDeclaringClass(), serializationConfig);
        AnnotatedMethod annotatedField = AnnotatedMethodBuilder.build(annotatedClass, method, annotationMap, paramAnnotations);
        return Optional.of(serializationConfig.getPropertyNamingStrategy().nameForGetterMethod(serializationConfig, annotatedField, name));
    }
    return Optional.empty();
}
Also used : AnnotationMap(com.fasterxml.jackson.databind.introspect.AnnotationMap) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) AnnotatedClass(com.fasterxml.jackson.databind.introspect.AnnotatedClass) SerializationConfig(com.fasterxml.jackson.databind.SerializationConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Annotation(java.lang.annotation.Annotation)

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