下面列出了com.fasterxml.jackson.databind.util.Annotations#com.fasterxml.jackson.databind.introspect.AnnotatedParameter 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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);
}
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);
}
public Param(AnnotatedParameter p, BeanPropertyDefinition pd,
JacksonInject.Value i)
{
annotated = p;
propDef = pd;
injection = i;
}
@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);
}
}
@Override
public String findImplicitPropertyName(AnnotatedMember param) {
if (param instanceof AnnotatedParameter) {
return _paranamer.findParameterName((AnnotatedParameter) param);
}
return null;
}
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;
}
@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;
}
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);
}
}
public void configureIncompleteParameter(AnnotatedParameter parameter) {
_incompleteParameter = parameter;
}
@Override
public AnnotatedParameter getIncompleteParameter() {
return _incompleteParameter;
}
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
String defaultName)
{
return translate(defaultName);
}
@Override
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam,
String defaultName) {
return judgeStrategy(ctorParam).nameForConstructorParameter(config, ctorParam, defaultName);
}
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);
}
static Parameter getParameter(AnnotatedParameter ctorParam) {
Executable constructor = (Executable) ctorParam.getOwner().getMember();
return constructor.getParameters()[ctorParam.getIndex()];
}
@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));
}
/**
* @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;
}
/**
* 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; }
/**
* 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;
}
public AnnotatedParameter parameter(int i) { return _params[i].annotated; }
public abstract PropertyName findConstructorName(AnnotatedParameter p);