/** * Method used to find accessor (getter, field to access) to use for accessing * value of the property. * Null if no such member exists. */ public AnnotatedMember getAccessor() { AnnotatedMember m = getGetter(); if (m == null) { m = getField(); } return m; }
for (BeanPropertyDefinition definition : definitions) { if (definition.hasGetter() && Collection.class.isAssignableFrom(definition.getGetter().getRawType())) {
final AnnotatedField field = propDef.getField(); final AnnotatedMethod setter = propDef.getSetter(); final AnnotatedMethod getter = propDef.getGetter(); final List<Annotation> paramAnnotations = new ArrayList<Annotation>(); final Iterator<OpenAPIExtension> extensions = OpenAPIExtensions.chain();
/** * Method that will construct a regular bean property setter using * the given setter method. */ protected SettableBeanProperty constructSetterlessProperty(DeserializationContext ctxt, BeanDescription beanDesc, BeanPropertyDefinition propDef) throws JsonMappingException { final AnnotatedMethod getter = propDef.getGetter(); JavaType type = resolveMemberAndTypeAnnotations(ctxt, getter, getter.getType()); TypeDeserializer typeDeser = type.getTypeHandler(); SettableBeanProperty prop = new SetterlessProperty(propDef, type, typeDeser, beanDesc.getClassAnnotations(), getter); JsonDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, getter); if (deser == null) { deser = type.getValueHandler(); } if (deser != null) { deser = ctxt.handlePrimaryContextualization(deser, prop, type); prop = prop.withValueDeserializer(deser); } return prop; }
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(); }
} else { AnnotatedMethod getter = propDef.getGetter(); if (getter != null) { if (useGettersAsSetters && _isSetterlessType(getter.getRawType())) {
private List<Descriptor> createJacksonDescriptor(String name, Class<?> type) { List<Descriptor> descriptors = new ArrayList<Descriptor>(); for (BeanPropertyDefinition definition : new JacksonMetadata(mapper, type)) { AnnotatedMethod getter = definition.getGetter(); Description description = getter.getAnnotation(Description.class); ResourceDescription fallback = SimpleResourceDescription .defaultFor(String.format("%s.%s", name, definition.getName())); ResourceDescription resourceDescription = description == null ? null : new AnnotationBasedResourceDescription(description, fallback); descriptors.add(// descriptor().// name(definition.getName()).// type(Type.SEMANTIC).// doc(getDocFor(resourceDescription)).// build()); } return descriptors; }
@SuppressWarnings("unchecked") public static <T> T initGetter(BeanPropertyDefinition propertyDefinition) { if (propertyDefinition.hasGetter()) { return LambdaMetafactoryUtils.createGetter(propertyDefinition.getGetter().getAnnotated()); } if (propertyDefinition.hasField() && propertyDefinition.getField().isPublic()) { return (T) LambdaMetafactoryUtils.createGetter(propertyDefinition.getField().getAnnotated()); } return null; }
/** * Method used to find accessor (getter, field to access) to use for accessing * value of the property. * Null if no such member exists. */ public AnnotatedMember getAccessor() { AnnotatedMember m = getGetter(); if (m == null) { m = getField(); } return m; }
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> tryGetGetterAnnotation( BeanPropertyDefinition beanPropertyDefinition, Class<A> annotationClass) { try { if (beanPropertyDefinition.hasGetter()) { return Optional.fromNullable(beanPropertyDefinition.getGetter().getAnnotation(annotationClass)); } } catch (IllegalArgumentException ignored) { } return Optional.absent(); } @SuppressWarnings("PMD")
@SuppressWarnings("PMD") private static <A extends Annotation> Optional<A> tryGetGetterAnnotation( BeanPropertyDefinition beanPropertyDefinition, Class<A> annotationClass) { if (beanPropertyDefinition.hasGetter()) { return Optional.fromNullable(beanPropertyDefinition.getGetter().getAnnotation(annotationClass)); } return Optional.absent(); }
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); }
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); } }
private List<Descriptor> createJacksonDescriptor(String name, Class<?> type) { List<Descriptor> descriptors = new ArrayList<Descriptor>(); for (BeanPropertyDefinition definition : new JacksonMetadata(mapper, type)) { AnnotatedMethod getter = definition.getGetter(); Description description = getter.getAnnotation(Description.class); ResourceDescription fallback = SimpleResourceDescription .defaultFor(String.format("%s.%s", name, definition.getName())); ResourceDescription resourceDescription = description == null ? null : new AnnotationBasedResourceDescription(description, fallback); descriptors.add(// descriptor().// name(definition.getName()).// type(Type.SEMANTIC).// doc(getDocFor(resourceDescription)).// build()); } return descriptors; }
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 Getter initGetter(BeanPropertyDefinition propertyDefinition) throws Throwable { if (propertyDefinition.hasGetter()) { return LambdaMetafactoryUtils.createGetter(propertyDefinition.getGetter().getAnnotated()); } if (propertyDefinition.hasField() && propertyDefinition.getField().isPublic()) { return LambdaMetafactoryUtils.createGetter(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; }
/** * Method that will construct a regular bean property setter using * the given setter method. */ protected SettableBeanProperty constructSetterlessProperty(DeserializationContext ctxt, BeanDescription beanDesc, BeanPropertyDefinition propDef) throws JsonMappingException { final AnnotatedMethod getter = propDef.getGetter(); JavaType type = resolveMemberAndTypeAnnotations(ctxt, getter, getter.getType()); TypeDeserializer typeDeser = type.getTypeHandler(); SettableBeanProperty prop = new SetterlessProperty(propDef, type, typeDeser, beanDesc.getClassAnnotations(), getter); JsonDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, getter); if (deser == null) { deser = type.getValueHandler(); } if (deser != null) { deser = ctxt.handlePrimaryContextualization(deser, prop, type); prop = prop.withValueDeserializer(deser); } return prop; }