com.fasterxml.jackson.databind.introspect.Annotated Java Examples

The following examples show how to use com.fasterxml.jackson.databind.introspect.Annotated. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: jackson-modules-base   Author: FasterXML   File: ParanamerAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(MapperConfig<?> config, Annotated a)
{
    /* 14-Apr-2014, tatu: Important -- we should NOT introspect name here,
     *   since we are not using annotations; instead it needs to be done
     *   in {@link #findParameterSourceName(AnnotatedParameter)}.
     */
    /*
    PropertyName name = super.findNameForDeserialization(a);
    if (name == null) {
        if (a instanceof AnnotatedParameter) {
            String rawName _paranamer.findParameterName((AnnotatedParameter) a);
            if (rawName != null) {
                return new PropertyName(rawName);
            }
        }
    }
    */
    return null;
}
 
Example #2
Source Project: jackson-lombok   Author: xebia   File: JacksonLombokAnnotationIntrospector.java    License: MIT License 6 votes vote down vote up
@Override
public boolean hasCreatorAnnotation(Annotated annotated) {
    if (super.hasCreatorAnnotation(annotated)) {
        return true;
    } else if (!(annotated instanceof AnnotatedConstructor)) {
        return false;
    } else {
        AnnotatedConstructor annotatedConstructor = (AnnotatedConstructor) annotated;

        ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);

        if (properties == null) {
            return false;
        } else {
            addJacksonAnnotationsToContructorParameters(annotatedConstructor);
            return true;
        }
    }
}
 
Example #3
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<?> findSerializer(Annotated a) {
  StoredAsJson storedAsJson = a.getAnnotation(StoredAsJson.class);
  RosettaSerialize rosettaSerialize = a.getAnnotation(RosettaSerialize.class);
  if (storedAsJson != null && rosettaSerialize != null) {
    throw new IllegalArgumentException("Cannot have @StoredAsJson as well as @RosettaSerialize annotations on the same entry");
  }
  if (storedAsJson != null) {
    Class<?> type = a.getRawType();
    return storedAsJson.binary() ? new StoredAsJsonBinarySerializer(type) : new StoredAsJsonSerializer(type);
  }

  if (rosettaSerialize != null) {
    Class<? extends JsonSerializer> klass = rosettaSerialize.using();
    if (klass != JsonSerializer.None.class) {
      return ClassUtil.createInstance(
          klass,
          objectMapper.getSerializationConfig().canOverrideAccessModifiers());
    }
  }
  return null;
}
 
Example #4
Source Project: haven-platform   Author: codeabovelab   File: KvSupportModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object findDeserializationConverter(Annotated a) {
    Class<? extends PropertyInterceptor>[] interceptors = getInterceptors(a);
    if (interceptors == null) {
        return null;
    }
    JavaType javaType = a.getType();
    if(a instanceof AnnotatedMethod) {
        AnnotatedMethod am = (AnnotatedMethod) a;
        if(am.getParameterCount() == 1) {
            javaType = am.getParameterType(0);
        } else {
            throw new RuntimeException("Invalid property setter: " + am.getAnnotated());
        }
    }
    return new KvInterceptorsDeserializationConverter(interceptors, new KvPropertyContextImpl(a, javaType));
}
 
Example #5
Source Project: netty-rest   Author: buremba   File: SwaggerJacksonAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<NamedType> findSubtypes(Annotated a)
{
    final ApiModel api = a.getAnnotation(ApiModel.class);
    if (api != null) {
        final Class<?>[] classes = api.subTypes();
        final List<NamedType> names = new ArrayList<>(classes.length);
        for (Class<?> subType : classes) {
            names.add(new NamedType(subType));
        }
        if (!names.isEmpty()) {
            return names;
        }
    }

    return Collections.emptyList();
}
 
Example #6
Source Project: netty-rest   Author: buremba   File: SwaggerJacksonAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String findPropertyDescription(Annotated a)
{
    ApiParam apiParam = a.getAnnotation(ApiParam.class);
    if (apiParam != null) {
        return apiParam.description();
    }

    ApiModel model = a.getAnnotation(ApiModel.class);
    if (model != null && !"".equals(model.description())) {
        return model.description();
    }
    ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
    if (prop != null) {
        return prop.value();
    }
    return null;
}
 
Example #7
Source Project: cloudstack   Author: apache   File: CSJacksonAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object findSerializer(Annotated a) {
    AnnotatedElement ae = a.getAnnotated();
    Url an = ae.getAnnotation(Url.class);
    if (an == null) {
        return null;
    }

    if (an.type() == String.class) {
        return new UriSerializer(an);
    } else if (an.type() == List.class) {
        return new UrisSerializer(an);
    }

    throw new UnsupportedOperationException("Unsupported type " + an.type());

}
 
Example #8
Source Project: graphql-spqr   Author: leangen   File: JacksonValueMapper.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isIncluded(AnnotatedType declaringType, BeanPropertyDefinition prop, boolean deserializableInSubType, InclusionStrategy inclusionStrategy) {
    List<AnnotatedElement> elements = Utils.flatten(
            Optional.ofNullable(prop.getConstructorParameter()).map(ElementFactory::getParameter),
            Optional.ofNullable(prop.getSetter()).map(Annotated::getAnnotated),
            Optional.ofNullable(prop.getGetter()).map(Annotated::getAnnotated),
            Optional.ofNullable(prop.getField()).map(Annotated::getAnnotated))
            .collect(Collectors.toList());

    InputFieldInclusionParams params = InputFieldInclusionParams.builder()
            .withType(declaringType)
            .withElementDeclaringClass(prop.getPrimaryMember().getDeclaringClass())
            .withElements(elements)
            .withDeserializationInfo(prop.couldDeserialize(), deserializableInSubType)
            .build();

    return inclusionStrategy.includeInputField(params);
}
 
Example #9
Source Project: haven-platform   Author: codeabovelab   File: JtModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object findDeserializationConverter(Annotated a) {
    JtToMap ann = a.getAnnotation(JtToMap.class);
    if (ann == null) {
        return null;
    }
    JavaType javaType = a.getType();
    if(a instanceof AnnotatedMethod) {
        AnnotatedMethod am = (AnnotatedMethod) a;
        if(am.getParameterCount() == 1) {
            javaType = am.getParameterType(0);
        } else {
            throw new RuntimeException("Invalid property setter: " + am.getAnnotated());
        }
    }
    return new DeserializationConverterImpl(ann, new Ctx(a, javaType));
}
 
Example #10
Source Project: friendly-id   Author: Devskiller   File: FriendlyIdAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object findSerializer(Annotated annotatedMethod) {
	IdFormat annotation = _findAnnotation(annotatedMethod, IdFormat.class);
	if (annotatedMethod.getRawType() == UUID.class) {
		if (annotation != null) {
			switch (annotation.value()) {
				case RAW:
					return UUIDSerializer.class;
				case URL62:
					return FriendlyIdSerializer.class;
			}
		}
		return FriendlyIdSerializer.class;
	} else {
		return null;
	}
}
 
Example #11
Source Project: friendly-id   Author: Devskiller   File: FriendlyIdAnnotationIntrospector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object findDeserializer(Annotated annotatedMethod) {
	IdFormat annotation = _findAnnotation(annotatedMethod, IdFormat.class);
	if (rawDeserializationType(annotatedMethod) == UUID.class) {
		if (annotation != null) {
			switch (annotation.value()) {
				case RAW:
					return UUIDDeserializer.class;
				case URL62:
					return FriendlyIdDeserializer.class;
			}
		}
		return FriendlyIdDeserializer.class;
	} else {
		return null;
	}
}
 
Example #12
Source Project: haven-platform   Author: codeabovelab   File: JtModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object findSerializationConverter(Annotated a) {
    JtToMap ann = a.getAnnotation(JtToMap.class);
    if (ann == null) {
        return null;
    }
    return new SerializationConverterImpl(ann, new Ctx(a, a.getType()));
}
 
Example #13
Source Project: netty-rest   Author: buremba   File: SwaggerJacksonAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a)
{
    ApiParam model = a.getAnnotation(ApiParam.class);
    if (model != null && !"".equals(model.value())) {
        return new PropertyName(model.value());
    }
    return null;
}
 
Example #14
Source Project: spring-analysis-note   Author: Vip-Augus   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ValueInstantiator valueInstantiatorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ValueInstantiator) this.beanFactory.createBean(implClass);
}
 
Example #15
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
private PropertyName findRosettaPropertyName(Annotated a) {
  RosettaProperty ann = a.getAnnotation(RosettaProperty.class);
  if (ann != null) {
    return ann.value().isEmpty() ? PropertyName.USE_DEFAULT : new PropertyName(ann.value());
  }
  return null;
}
 
Example #16
Source Project: spring-analysis-note   Author: Vip-Augus   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (ObjectIdResolver) this.beanFactory.createBean(implClass);
}
 
Example #17
Source Project: spring-analysis-note   Author: Vip-Augus   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public PropertyNamingStrategy namingStrategyInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (PropertyNamingStrategy) this.beanFactory.createBean(implClass);
}
 
Example #18
Source Project: spring-analysis-note   Author: Vip-Augus   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public Converter<?, ?> converterInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (Converter<?, ?>) this.beanFactory.createBean(implClass);
}
 
Example #19
Source Project: haven-platform   Author: codeabovelab   File: KvSupportModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object findSerializationConverter(Annotated a) {
    Class<? extends PropertyInterceptor>[] interceptors = getInterceptors(a);
    if (interceptors == null) {
        return null;
    }
    return new KvInterceptorsSerializationConverter(interceptors, new KvPropertyContextImpl(a, a.getType()));
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public PropertyNamingStrategy namingStrategyInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (PropertyNamingStrategy) this.beanFactory.createBean(implClass);
}
 
Example #21
Source Project: java-technology-stack   Author: codeEngraver   File: SpringHandlerInstantiator.java    License: MIT License 5 votes vote down vote up
/** @since 4.3 */
@Override
public Converter<?, ?> converterInstance(MapperConfig<?> config,
		Annotated annotated, Class<?> implClass) {

	return (Converter<?, ?>) this.beanFactory.createBean(implClass);
}
 
Example #22
Source Project: onedev   Author: theonedev   File: HibernateAnnotationIntrospector.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Object findSerializer(Annotated am) {
	if (am.hasAnnotation(ManyToOne.class)) {
		return new ManyToOneSerializer((Class<AbstractEntity>) am.getRawType());
	} else {
		return super.findDeserializer(am);
	}
}
 
Example #23
Source Project: conjure   Author: palantir   File: KebabCaseEnforcingAnnotationInspector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated annotatedEntity) {
    // This logic relies on the fact that Immutables generates setters annotated with @JsonProperty.
    // It thus becomes obsolete whenever we move away from Immutables and the deserialization target no longer
    // carries those annotations.

    JsonProperty propertyAnnotation = _findAnnotation(annotatedEntity, JsonProperty.class);
    if (propertyAnnotation != null) {
        String jsonFieldName = propertyAnnotation.value();
        Preconditions.checkArgument(
                KEBAB_CASE_PATTERN.matcher(jsonFieldName).matches(),
                "Conjure grammar requires kebab-case field names: %s",
                jsonFieldName);
    }

    if (annotatedEntity instanceof AnnotatedMethod) {
        AnnotatedMethod maybeSetter = (AnnotatedMethod) annotatedEntity;
        if (maybeSetter.getName().startsWith("set")) {
            // As a pre-caution, require that all setters have a JsonProperty annotation.
            Preconditions.checkArgument(
                    _findAnnotation(annotatedEntity, JsonProperty.class) != null,
                    "All setter ({@code set*}) deserialization targets require @JsonProperty annotations: %s",
                    maybeSetter.getName());
        }
    }

    return null; // delegate to the next introspector in an AnnotationIntrospectorPair.
}
 
Example #24
Source Project: requery   Author: requery   File: ResolverInstantiator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ObjectIdResolver resolverIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) {
    if (implClass.isAssignableFrom(EntityStoreResolver.class)) {
        return new EntityStoreResolver(store);
    }
    return null;
}
 
Example #25
Source Project: elepy   Author: RyanSusana   File: CustomAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a) {
    String rawName = findPropertyName(a);
    if (rawName != null) {
        return new PropertyName(rawName);
    }
    return null;
}
 
Example #26
Source Project: elepy   Author: RyanSusana   File: CustomAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
private String findPropertyName(Annotated annotated) {

        if (isId(annotated)) {
            return "_id";
        }
        return null;
    }
 
Example #27
Source Project: Rosetta   Author: HubSpot   File: RosettaAnnotationIntrospector.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PropertyName findNameForDeserialization(Annotated a) {
  PropertyName propertyName = findRosettaPropertyName(a);
  if (propertyName == null) {
    propertyName = super.findNameForDeserialization(a);
  }
  return propertyName;
}
 
Example #28
Source Project: pinpoint   Author: naver   File: ServerInstanceListSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
public JsonSerializer<?> serializerInstance(SerializationConfig config, Annotated annotated, Class<?> keyDeserClass) {
    if (annotated.getName().equals("com.navercorp.pinpoint.web.applicationmap.nodes.ServerInstance")) {
        final ServiceTypeRegistryService serviceTypeRegistryService = mockServiceTypeRegistryService();
        final AgentLifeCycleStateSerializer agentLifeCycleStateSerializer = new AgentLifeCycleStateSerializer();

        return new ServerInstanceSerializer(serviceTypeRegistryService, agentLifeCycleStateSerializer);
    }
    return null;
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: MapperConfig.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method that can be called to obtain an instance of <code>TypeIdResolver</code> of
 * specified type.
 */
public TypeResolverBuilder<?> typeResolverBuilderInstance(Annotated annotated,
        Class<? extends TypeResolverBuilder<?>> builderClass)
{
    HandlerInstantiator hi = getHandlerInstantiator();
    if (hi != null) {
        TypeResolverBuilder<?> builder = hi.typeResolverBuilderInstance(this, annotated, builderClass);
        if (builder != null) {
            return builder;
        }
    }
    return (TypeResolverBuilder<?>) ClassUtil.createInstance(builderClass, canOverrideAccessModifiers());
}
 
Example #30
Source Project: lams   Author: lamsfoundation   File: MapperConfig.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method that can be called to obtain an instance of <code>TypeIdResolver</code> of
 * specified type.
 */
public TypeIdResolver typeIdResolverInstance(Annotated annotated,
        Class<? extends TypeIdResolver> resolverClass)
{
    HandlerInstantiator hi = getHandlerInstantiator();
    if (hi != null) {
        TypeIdResolver builder = hi.typeIdResolverInstance(this, annotated, resolverClass);
        if (builder != null) {
            return builder;
        }
    }
    return (TypeIdResolver) ClassUtil.createInstance(resolverClass, canOverrideAccessModifiers());
}