List of usage examples for com.fasterxml.jackson.databind.introspect BeanPropertyDefinition getGetter
public abstract AnnotatedMethod getGetter();
From source file:springfox.bean.validators.plugins.Validators.java
private static Optional<Method> extractGetterFromPropertyDefinition(BeanPropertyDefinition propertyDefinition) { if (propertyDefinition.getGetter() != null) { return Optional.fromNullable(propertyDefinition.getGetter().getMember()); }// w w w.jav a2 s .c om return Optional.absent(); }
From source file:springfox.documentation.schema.Annotations.java
@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)); }/*w w w.java 2s . c om*/ return Optional.absent(); }
From source file:com.google.api.server.spi.config.jsonwriter.JacksonResourceSchemaProvider.java
@Override public ResourceSchema getResourceSchema(TypeToken<?> type, ApiConfig config) { ResourceSchema schema = super.getResourceSchema(type, config); if (schema != null) { return schema; }/*from ww w .j a v a2 s. c o m*/ ObjectMapper objectMapper = ObjectMapperUtil.createStandardObjectMapper(config.getSerializationConfig()); JavaType javaType = objectMapper.getTypeFactory().constructType(type.getRawType()); BeanDescription beanDescription = objectMapper.getSerializationConfig().introspect(javaType); ResourceSchema.Builder schemaBuilder = ResourceSchema.builderForType(type.getRawType()); Set<String> genericDataFieldNames = getGenericDataFieldNames(type); for (BeanPropertyDefinition definition : beanDescription.findProperties()) { TypeToken<?> propertyType = getPropertyType(type, toMethod(definition.getGetter()), toMethod(definition.getSetter()), definition.getField(), config); String name = definition.getName(); if (genericDataFieldNames == null || genericDataFieldNames.contains(name)) { if (hasUnresolvedType(propertyType)) { logger.warning("skipping field '" + name + "' of type '" + propertyType + "' because it is unresolved."); continue; } if (propertyType != null) { schemaBuilder.addProperty(name, ResourcePropertySchema.of(propertyType)); } else { logger.warning("No type found for property '" + name + "' on class '" + type + "'."); } } else { logger.fine("skipping field '" + name + "' because it's not a Java client model field."); } } return schemaBuilder.build(); }
From source file:fr.norad.jaxrs.doc.parser.ModelJacksonParser.java
@Override public List<PropertyAccessor> findProperties(Class<?> modelClass) { List<PropertyAccessor> properties = new ArrayList<>(); BasicBeanDescription beanDesc = fakeSerializer.getDescription(modelClass); List<BeanPropertyDefinition> findProperties = beanDesc.findProperties(); for (BeanPropertyDefinition beanPropertyDefinition : findProperties) { if (modelClass.isEnum() && "declaringClass".equals(beanPropertyDefinition.getName())) { continue; }/*from w ww .j a v a 2 s.c om*/ AnnotatedMethod getterJackson = beanPropertyDefinition.getGetter(); AnnotatedMethod setterJackson = beanPropertyDefinition.getSetter(); AnnotatedField fieldJackson = null; try { fieldJackson = beanPropertyDefinition.getField(); } catch (Exception e) { log.warning("Name conflict on fields in bean : " + beanPropertyDefinition + " during doc generation" + e.getMessage()); } Method getter = getterJackson == null ? null : getterJackson.getAnnotated(); Method setter = setterJackson == null ? null : setterJackson.getAnnotated(); Field field = fieldJackson == null ? null : fieldJackson.getAnnotated(); if (getter == null && setter == null && field == null) { log.warning( "Cannot find valid property element for : " + beanPropertyDefinition + " on " + modelClass); continue; } PropertyAccessor property = new PropertyAccessor(); property.setField(field); property.setGetter(getter); property.setSetter(setter); property.setName(beanPropertyDefinition.getName()); properties.add(property); } return properties; }
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
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());// ww w . j a v a2s .c o m } return descriptors; }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
private void parseProperty(ModelConverterContext context, boolean isNested, final BeanDescription beanDesc, Set<String> propertiesToIgnore, List<Property> props, BeanPropertyDefinition propDef) { Property property = null;/*from ww w . j av a2 s . com*/ String propName = propDef.getName(); Annotation[] annotations = null; propName = getPropName(propDef, propName); PropertyMetadata md = propDef.getMetadata(); boolean hasSetter = false, hasGetter = false; if (propDef.getSetter() == null) { hasSetter = false; } else { hasSetter = true; } if (propDef.getGetter() != null) { JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class); if (pd != null) { hasGetter = true; } } Boolean isReadOnly = null; if (!hasSetter & hasGetter) { isReadOnly = Boolean.TRUE; } else { isReadOnly = Boolean.FALSE; } final AnnotatedMember member = propDef.getPrimaryMember(); if (member != null && !propertiesToIgnore.contains(propName) && /** * If the owning type is nested than we should include only those * fields that have the Hateoas annotation. */ !(isNested && !member.hasAnnotation(HateoasInclude.class))) { List<Annotation> annotationList = new ArrayList<Annotation>(); for (Annotation a : member.annotations()) { annotationList.add(a); } annotations = annotationList.toArray(new Annotation[annotationList.size()]); ApiModelProperty mp = member.getAnnotation(ApiModelProperty.class); if (mp != null && mp.readOnly()) { isReadOnly = mp.readOnly(); } Type nested = null; JavaType propType = member.getType(beanDesc.bindingsForBeanType()); JsonFilter jsonFilter = propType.getRawClass().getAnnotation(JsonFilter.class); /** * At this point the propType is a type of some nested field of the * type that is being processed. The condition checks if this * particular type should have Hateoas serialization enabled. In * other words, if we should create a new Nested* model. */ if (jsonFilter != null && (jsonFilter.value().equals("ConsumerFilter") || jsonFilter.value().equals("EntitlementFilter") || jsonFilter.value().equals("OwnerFilter") || jsonFilter.value().equals("GuestFilter"))) { if (!nestedJavaTypes.containsKey(propType)) { nestedJavaTypes.put(propType, new NestedComplexType(propType)); } nested = nestedJavaTypes.get(propType); } else { nested = propType; } // allow override of name from annotation if (mp != null && !mp.name().isEmpty()) { propName = mp.name(); } if (mp != null && !mp.dataType().isEmpty()) { property = resolveApiAnnotated(context, property, annotations, mp, propType); } // no property from override, construct from propType if (property == null) { if (mp != null && StringUtils.isNotEmpty(mp.reference())) { property = new RefProperty(mp.reference()); } else if (member.getAnnotation(JsonIdentityInfo.class) != null) { property = GeneratorWrapper.processJsonIdentity(propType, context, pMapper, member.getAnnotation(JsonIdentityInfo.class), member.getAnnotation(JsonIdentityReference.class)); } if (property == null) { property = context.resolveProperty(nested, annotations); } } if (property != null) { addMetadataToProperty(property, propName, md, isReadOnly, member, mp); applyBeanValidatorAnnotations(property, annotations); props.add(property); } } }