/** * @since 2.3 */ public AnnotatedMember getNonConstructorMutator() { AnnotatedMember m = getSetter(); if (m == null) { m = getField(); } return m; }
/** * Method used to find mutator (constructor parameter, setter, field) to use for * changing value of the property. * Null if no such member exists. */ public AnnotatedMember getMutator() { AnnotatedMember acc = getConstructorParameter(); if (acc == null) { acc = getSetter(); if (acc == null) { acc = getField(); } } return acc; }
final AnnotatedMethod setter = propDef.getSetter(); final AnnotatedMethod getter = propDef.getGetter(); final List<Annotation> paramAnnotations = new ArrayList<Annotation>();
private static Optional<AnnotatedMember> findAnnotatedMember(BeanPropertyDefinition property) { if (property.getPrimaryMember() != null) { return Optional.of(property.getPrimaryMember()); } if (property.getGetter() != null) { return Optional.of(property.getGetter()); } if (property.getSetter() != null) { return Optional.of(property.getSetter()); } return Optional.empty(); }
AnnotatedMethod setter = propDef.getSetter(); JavaType propertyType = setter.getParameterType(0); prop = constructSettableProperty(ctxt, beanDesc, propDef, propertyType);
protected Object initSetter(BeanPropertyDefinition propertyDefinition) throws Throwable { if (propertyDefinition.hasSetter()) { return LambdaMetafactoryUtils.createSetter(propertyDefinition.getSetter().getAnnotated()); } if (propertyDefinition.hasField() && propertyDefinition.getField().isPublic()) { return LambdaMetafactoryUtils.createSetter(propertyDefinition.getField().getAnnotated()); } return null; } }
/** * @since 2.3 */ public AnnotatedMember getNonConstructorMutator() { AnnotatedMember m = getSetter(); if (m == null) { m = getField(); } return m; }
@SuppressWarnings("PMD") private static <A extends Annotation> Optional<A> tryGetSetterAnnotation( BeanPropertyDefinition beanPropertyDefinition, Class<A> annotationClass) { if (beanPropertyDefinition.hasSetter()) { return Optional.fromNullable(beanPropertyDefinition.getSetter().getAnnotation(annotationClass)); } return Optional.absent(); }
private static Optional<AnnotatedMember> findAnnotatedMember(BeanPropertyDefinition property) { if (property.getPrimaryMember() != null) { return Optional.of(property.getPrimaryMember()); } if (property.getGetter() != null) { return Optional.of(property.getGetter()); } if (property.getSetter() != null) { return Optional.of(property.getSetter()); } return Optional.empty(); }
@SuppressWarnings("PMD") private static <A extends Annotation> Optional<A> tryGetSetterAnnotation( BeanPropertyDefinition beanPropertyDefinition, Class<A> annotationClass) { try { if (beanPropertyDefinition.hasSetter()) { return Optional.fromNullable(beanPropertyDefinition.getSetter().getAnnotation(annotationClass)); } } catch (IllegalArgumentException ignored) { } return Optional.absent(); } @SuppressWarnings("PMD")
/** * Method used to find mutator (constructor parameter, setter, field) to use for * changing value of the property. * Null if no such member exists. */ public AnnotatedMember getMutator() { AnnotatedMember acc = getConstructorParameter(); if (acc == null) { acc = getSetter(); if (acc == null) { acc = getField(); } } return acc; }
protected Object defaultValue(AnnotatedType type, BeanPropertyDefinition prop, AnnotatedType fieldType, TypeTransformer typeTransformer, GlobalEnvironment environment) { List<AnnotatedElement> annotatedCandidates = new ArrayList<>(4); PropertyDescriptorFactory descFactory = new PropertyDescriptorFactory(type, typeTransformer); AnnotatedParameter ctorParam = prop.getConstructorParameter(); if (ctorParam != null) { annotatedCandidates.add(descFactory.fromConstructorParameter(ctorParam).element); } if (prop.getSetter() != null) { annotatedCandidates.add(descFactory.fromSetter(prop.getSetter()).element); } if (prop.getGetter() != null) { annotatedCandidates.add(descFactory.fromGetter(prop.getGetter()).element); } if (prop.getField() != null) { annotatedCandidates.add(descFactory.fromField(prop.getField()).element); } return inputInfoGen.defaultValue(annotatedCandidates, fieldType, environment).orElse(null); }
private List<ConstructibleAnnotatedCollection> collectFields(final DeserializationConfig config, final BeanDescription desc) { final List<ConstructibleAnnotatedCollection> fields = new ArrayList<ConstructibleAnnotatedCollection>(); final Map<String, AnnotatedMethod> setters = new LinkedHashMap<String, AnnotatedMethod>(); List<BeanPropertyDefinition> properties = desc.findProperties(); for (BeanPropertyDefinition beanPropertyDefinition : properties) { setters.put(beanPropertyDefinition.getInternalName(), beanPropertyDefinition.getSetter()); } ReflectionUtils.eachField(desc.getType().getRawClass(), new Predicate<Field>() { @Override public boolean apply(Field input) { if (ReflectionUtils.hasAnnotation(input, DocumentReferences.class)) { ConstructibleAnnotatedCollection c = collectBackrefField(config, desc, setters, input); if (c != null) { fields.add(c); } } return false; } }); return fields; }
public PropertyDescriptor getPropertyDescriptor(String propertyName, Class<?> confClass) throws IntrospectionException { if (mapper != null) { JavaType configType = mapper.constructType(confClass); BeanDescription configDescr = mapper.getSerializationConfig().introspect(configType); List<BeanPropertyDefinition> configProps = configDescr.findProperties(); for (BeanPropertyDefinition prop : configProps) { if (prop.getName().equals(propertyName)) { Method readMethod = prop.hasGetter() ? prop.getGetter().getMember() : null; Method writeMethod = prop.hasSetter() ? prop.getSetter().getMember() : null; return new PropertyDescriptor(propertyName, readMethod, writeMethod); } } } return new PropertyDescriptor(propertyName, confClass); } }
Class<?> rawPropertyType = null; if (property.hasSetter()) { rawPropertyType = property.getSetter().getRawParameterType(0); } else if (property.hasField()) { rawPropertyType = property.getField().getRawType();
Class<?> rawPropertyType = null; if (property.hasSetter()) { rawPropertyType = property.getSetter().getRawParameterType(0); } else if (property.hasField()) { rawPropertyType = property.getField().getRawType();
private Stream<InputField> toInputField(AnnotatedType type, BeanPropertyDefinition prop, GlobalEnvironment environment) { PropertyDescriptorFactory descFactory = new PropertyDescriptorFactory(type, environment.typeTransformer); AnnotatedParameter ctorParam = prop.getConstructorParameter(); if (ctorParam != null) { return toInputField(descFactory.fromConstructorParameter(ctorParam), prop, objectMapper, environment); } if (prop.getSetter() != null) { return toInputField(descFactory.fromSetter(prop.getSetter()), prop, objectMapper, environment); } if (prop.getGetter() != null) { return toInputField(descFactory.fromGetter(prop.getGetter()), prop, objectMapper, environment); } if (prop.getField() != null) { return toInputField(descFactory.fromField(prop.getField()), prop, objectMapper, environment); } throw new TypeMappingException("Unknown input field mapping style encountered"); }
protected Setter initSetter(BeanPropertyDefinition propertyDefinition) throws Throwable { if (propertyDefinition.hasSetter()) { return LambdaMetafactoryUtils.createSetter(propertyDefinition.getSetter().getAnnotated()); } if (propertyDefinition.hasField() && propertyDefinition.getField().isPublic()) { return LambdaMetafactoryUtils.createSetter(propertyDefinition.getField().getAnnotated()); } return null; }
/** * Finds first annotation of the given type on the given bean property and returns it. * Search precedence is getter -> setter -> field. * * @param beanPropertyDefinition introspected jackson proprty defintion * @param annotationClass class object representing desired annotation * @param <A> type that extends Annotation * @return first annotation found for property */ public static <A extends Annotation> A findPropertyAnnotation(BeanPropertyDefinition beanPropertyDefinition, Class<A> annotationClass) { A annotation = null; if (beanPropertyDefinition.hasGetter()) { annotation = beanPropertyDefinition.getGetter().getAnnotation(annotationClass); } if (annotation == null && beanPropertyDefinition.hasSetter()) { annotation = beanPropertyDefinition.getSetter().getAnnotation(annotationClass); } if (annotation == null && beanPropertyDefinition.hasField()) { annotation = beanPropertyDefinition.getField().getAnnotation(annotationClass); } return annotation; }