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

The following examples show how to use com.fasterxml.jackson.databind.introspect.AnnotatedParameter. 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 File: Java7SupportImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public PropertyName findConstructorName(AnnotatedParameter p)
{
    AnnotatedWithParams ctor = p.getOwner();
    if (ctor != null) {
        ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
        if (props != null) {
            String[] names = props.value();
            int ix = p.getIndex();
            if (ix < names.length) {
                return PropertyName.construct(names[ix]);
            }
        }
    }
    return null;
}
 
Example #2
Source File: JacksonLombokAnnotationIntrospector.java    From jackson-lombok with MIT License 6 votes vote down vote up
private void addJacksonAnnotationsToConstructorParameter(Field field, AnnotatedParameter parameter, String name) {
    if (field != null) {
        for (Annotation a : field.getAnnotations()) {
            if (a.annotationType().getName().startsWith("com.fasterxml")) {
                if (a.annotationType() != JsonProperty.class) {
                    parameter.addOrOverride(a);
                } else {
                    JsonProperty jp = (JsonProperty) a;
                    if (!jp.value().equals("")) {
                        name = jp.value();
                    }
                }
            }
        }
    }

    JsonProperty jsonProperty =
            ProxyAnnotation.of(JsonProperty.class, Collections.singletonMap("value", name));
    parameter.addOrOverride(jsonProperty);
}
 
Example #3
Source File: CreatorCandidate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static CreatorCandidate construct(AnnotationIntrospector intr,
        AnnotatedWithParams creator, BeanPropertyDefinition[] propDefs)
{
    final int pcount = creator.getParameterCount();
    Param[] params = new Param[pcount];
    for (int i = 0; i < pcount; ++i) {
        AnnotatedParameter annParam = creator.getParameter(i);
        JacksonInject.Value injectId = intr.findInjectableValue(annParam);
        params[i] = new Param(annParam, (propDefs == null) ? null : propDefs[i], injectId);
    }
    return new CreatorCandidate(intr, creator, params, pcount);
}
 
Example #4
Source File: JacksonLombokAnnotationIntrospector.java    From jackson-lombok with MIT License 5 votes vote down vote up
private void addJacksonAnnotationsToContructorParameters(AnnotatedConstructor annotatedConstructor) {
    ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);
    for (int i = 0; i < annotatedConstructor.getParameterCount(); i++) {
        String name = properties.value()[i];
        AnnotatedParameter parameter = annotatedConstructor.getParameter(i);
        Field field = null;
        try {
            field = annotatedConstructor.getDeclaringClass().getDeclaredField(name);
        } catch (NoSuchFieldException ignored) {
        }
        addJacksonAnnotationsToConstructorParameter(field, parameter, name);
    }
}
 
Example #5
Source File: AutoMatterAnnotationIntrospector.java    From auto-matter with Apache License 2.0 5 votes vote down vote up
@Override
public String findImplicitPropertyName(final AnnotatedMember member) {
  final AutoMatter.Field field = member.getAnnotation(AutoMatter.Field.class);
  if (field == null) {
    return null;
  }
  if (member instanceof AnnotatedParameter) {
    return field.value();
  }
  if (member instanceof AnnotatedMethod) {
    return member.getName();
  }
  return null;
}
 
Example #6
Source File: SerializableParanamer.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public String findParameterName(AnnotatedParameter param)
{
    int index = param.getIndex();
    AnnotatedElement ctor = param.getOwner().getAnnotated();
    String[] names = _paranamer.lookupParameterNames((AccessibleObject) ctor, false);
    if (names != null && index < names.length) {
        return names[index];
    }
    return null;
}
 
Example #7
Source File: ParanamerAnnotationIntrospector.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
@Override
public String findImplicitPropertyName(AnnotatedMember param) {
    if (param instanceof AnnotatedParameter) {
        return _paranamer.findParameterName((AnnotatedParameter) param);
    }
    return null;
}
 
Example #8
Source File: EsPropertyNamingStrategy.java    From soundwave with Apache License 2.0 5 votes vote down vote up
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
                                          String defaultName) {

  if (ctorParam.getDeclaringClass() != effectiveType) {
    return fieldToJsonMapping
        .getOrDefault(defaultName,
            super.nameForConstructorParameter(config, ctorParam, defaultName));
  } else {
    return super.nameForConstructorParameter(config, ctorParam, defaultName);
  }
}
 
Example #9
Source File: CreatorCandidate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Param(AnnotatedParameter p, BeanPropertyDefinition pd,
        JacksonInject.Value i)
{
    annotated = p;
    propDef = pd;
    injection = i;
}
 
Example #10
Source File: PropertyNamingStrategy.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
        String defaultName)
{
    return translate(defaultName);
}
 
Example #11
Source File: StdValueInstantiator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void configureIncompleteParameter(AnnotatedParameter parameter) {
    _incompleteParameter = parameter;
}
 
Example #12
Source File: MattermostPropertyNamingStrategy.java    From mattermost4j with Apache License 2.0 4 votes vote down vote up
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
    String defaultName) {
  return judgeStrategy(ctorParam).nameForConstructorParameter(config, ctorParam, defaultName);
}
 
Example #13
Source File: JacksonValueMapper.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
TypedElement fromConstructorParameter(AnnotatedParameter ctorParam) {
    Executable constructor = (Executable) ctorParam.getOwner().getMember();
    Parameter parameter = constructor.getParameters()[ctorParam.getIndex()];
    AnnotatedType fieldType = transform(ClassUtils.getParameterTypes(constructor, type)[ctorParam.getIndex()], parameter);
    return new TypedElement(fieldType, parameter);
}
 
Example #14
Source File: JacksonValueMapper.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
static Parameter getParameter(AnnotatedParameter ctorParam) {
    Executable constructor = (Executable) ctorParam.getOwner().getMember();
    return constructor.getParameters()[ctorParam.getIndex()];
}
 
Example #15
Source File: JsonldPropertyNamingStrategy.java    From jackson-jsonld with MIT License 4 votes vote down vote up
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam, String defaultName) {
    String name = config instanceof DeserializationConfig? jsonldName(ctorParam): null;
    return Optional.ofNullable(name).orElse(super.nameForConstructorParameter(config, ctorParam, defaultName));
}
 
Example #16
Source File: StdValueInstantiator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public AnnotatedParameter getIncompleteParameter() {
    return _incompleteParameter;
}
 
Example #17
Source File: CreatorProperty.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * @param name Name of the logical property
 * @param type Type of the property, used to find deserializer
 * @param typeDeser Type deserializer to use for handling polymorphic type
 *    information, if one is needed
 * @param contextAnnotations Contextual annotations (usually by class that
 *    declares creator [constructor, factory method] that includes
 *    this property)
 * @param param Representation of property, constructor or factory
 *    method parameter; used for accessing annotations of the property
 * @param index Index of this property within creator invocation
 * 
 * @since 2.3
 */
public CreatorProperty(PropertyName name, JavaType type, PropertyName wrapperName,
        TypeDeserializer typeDeser,
        Annotations contextAnnotations, AnnotatedParameter param,
        int index, Object injectableValueId,
        PropertyMetadata metadata)
{
    super(name, type, wrapperName, typeDeser, contextAnnotations, metadata);
    _annotated = param;
    _creatorIndex = index;
    _injectableValueId = injectableValueId;
    _fallbackSetter = null;
}
 
Example #18
Source File: PropertyNamingStrategy.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Method called to find external name (name used in JSON) for given logical
 * POJO property,
 * as defined by given constructor parameter; typically called when building a deserializer
 * (but not necessarily only then).
 * 
 * @param config Configuration in used: either <code>SerializationConfig</code>
 *   or <code>DeserializationConfig</code>, depending on whether method is called
 *   during serialization or deserialization
 * @param ctorParam Constructor parameter used to pass property.
 * @param defaultName Default name that would be used for property in absence of custom strategy
 */
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
        String defaultName)
{
    return defaultName;
}
 
Example #19
Source File: ValueInstantiator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * If an incomplete creator was found, this is the first parameter that
 * needs further annotation to help make the creator complete.
 */
public AnnotatedParameter getIncompleteParameter() { return null; }
 
Example #20
Source File: Java7Support.java    From lams with GNU General Public License v2.0 votes vote down vote up
public abstract PropertyName findConstructorName(AnnotatedParameter p); 
Example #21
Source File: CreatorCandidate.java    From lams with GNU General Public License v2.0 votes vote down vote up
public AnnotatedParameter parameter(int i) { return _params[i].annotated; }