List of usage examples for com.fasterxml.jackson.databind.introspect BeanPropertyDefinition getPrimaryMember
public AnnotatedMember getPrimaryMember()
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
private static boolean isObjectId(BeanPropertyDefinition property) { return property.getPrimaryMember().getAnnotation(org.jongo.marshall.jackson.oid.ObjectId.class) != null || property.getPrimaryMember().getAnnotation(MongoObjectId.class) != null || ObjectId.class.isAssignableFrom(property.getAccessor().getRawType()); }
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
private static boolean hasIdAnnotation(BeanPropertyDefinition property) { if (property == null) return false; AnnotatedMember accessor = property.getPrimaryMember(); return accessor != null && (accessor.getAnnotation(MongoId.class) != null || accessor.getAnnotation(Id.class) != null); }
From source file:springfox.documentation.schema.property.BaseModelProperty.java
public BaseModelProperty(String name, TypeResolver resolver, AlternateTypeProvider alternateTypeProvider, BeanPropertyDefinition jacksonProperty) { this.name = name; this.resolver = resolver; this.alternateTypeProvider = alternateTypeProvider; this.jacksonProperty = jacksonProperty; AnnotatedMember primaryMember = jacksonProperty.getPrimaryMember(); if (primaryMember != null) { jsonFormatAnnotation = Optional.fromNullable(primaryMember.getAnnotation(JsonFormat.class)); } else {/*www . j a v a 2s . co m*/ jsonFormatAnnotation = Optional.absent(); } }
From source file:springfox.documentation.schema.property.OptimizedModelPropertiesProvider.java
private AnnotatedMember safeGetPrimaryMember(BeanPropertyDefinition jacksonProperty) { try {/*from w w w .j a v a 2 s. c o m*/ return jacksonProperty.getPrimaryMember(); } catch (IllegalArgumentException e) { LOG.warn(String.format("Unable to get unique property. %s", e.getMessage())); return null; } }
From source file:springfox.documentation.schema.property.bean.BeanModelPropertyProvider.java
@Override public List<ModelProperty> propertiesFor(ResolvedType type, ModelContext givenContext) { List<ModelProperty> serializationCandidates = newArrayList(); BeanDescription beanDescription = beanDescription(type, givenContext); Map<String, BeanPropertyDefinition> propertyLookup = uniqueIndex(beanDescription.findProperties(), BeanPropertyDefinitions.beanPropertyByInternalName()); for (Map.Entry<String, BeanPropertyDefinition> each : propertyLookup.entrySet()) { BeanPropertyDefinition propertyDefinition = each.getValue(); Optional<BeanPropertyDefinition> jacksonProperty = jacksonPropertyWithSameInternalName(beanDescription, propertyDefinition);//from w w w . j a v a 2s. c o m AnnotatedMember member = propertyDefinition.getPrimaryMember(); Optional<ResolvedMethod> accessor = findAccessorMethod(type, each.getKey(), member); if (accessor.isPresent()) { serializationCandidates .addAll(addCandidateProperties(member, accessor.get(), jacksonProperty, givenContext)); } } return serializationCandidates; }
From source file:org.springframework.data.rest.webmvc.json.JacksonMetadata.java
/** * Returns the fallback {@link ResourceDescription} to be used for the given {@link BeanPropertyDefinition}. * //from www . jav a 2 s . com * @param ownerMetadata must not be {@literal null}. * @param definition must not be {@literal null}. * @return */ public ResourceDescription getFallbackDescription(ResourceMetadata ownerMetadata, BeanPropertyDefinition definition) { Assert.notNull(ownerMetadata, "Owner's resource metadata must not be null!"); Assert.notNull(definition, "BeanPropertyDefinition must not be null!"); AnnotatedMember member = definition.getPrimaryMember(); Description description = member.getAnnotation(Description.class); ResourceDescription fallback = TypedResourceDescription.defaultFor(ownerMetadata.getItemResourceRel(), definition.getInternalName(), definition.getPrimaryMember().getRawType()); return description == null ? fallback : new AnnotationBasedResourceDescription(description, fallback); }
From source file:springfox.documentation.schema.property.field.FieldModelPropertyProvider.java
@Override public List<ModelProperty> propertiesFor(ResolvedType type, ModelContext givenContext) { List<ModelProperty> serializationCandidates = newArrayList(); BeanDescription beanDescription = beanDescription(type, givenContext); Map<String, BeanPropertyDefinition> propertyLookup = Maps.uniqueIndex(beanDescription.findProperties(), BeanPropertyDefinitions.beanPropertyByInternalName()); for (ResolvedField childField : fieldProvider.in(type)) { if (propertyLookup.containsKey(childField.getName())) { BeanPropertyDefinition propertyDefinition = propertyLookup.get(childField.getName()); Optional<BeanPropertyDefinition> jacksonProperty = BeanPropertyDefinitions .jacksonPropertyWithSameInternalName(beanDescription, propertyDefinition); AnnotatedMember member = propertyDefinition.getPrimaryMember(); serializationCandidates.addAll(newArrayList( addSerializationCandidates(member, childField, jacksonProperty, givenContext))); }/*w w w . j a va2 s.co m*/ } return serializationCandidates; }
From source file:org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter.java
private List<AbstractJsonSchemaProperty<?>> getPropertiesFor(Class<?> type, final ResourceMetadata metadata, final Definitions definitions) { final PersistentEntity<?, ?> entity = entities.getPersistentEntity(type); final JacksonMetadata jackson = new JacksonMetadata(objectMapper, type); if (entity == null) { return Collections.<AbstractJsonSchemaProperty<?>>emptyList(); }//from ww w . ja va 2 s. c om JsonSchemaPropertyRegistrar registrar = new JsonSchemaPropertyRegistrar(jackson); for (BeanPropertyDefinition definition : jackson) { PersistentProperty<?> persistentProperty = entity.getPersistentProperty(definition.getInternalName()); // First pass, early drops to avoid unnecessary calculation if (persistentProperty != null) { if (persistentProperty.isIdProperty() && !configuration.isIdExposedFor(type)) { continue; } if (persistentProperty.isVersionProperty()) { continue; } if (!definition.couldSerialize()) { continue; } } AnnotatedMember primaryMember = definition.getPrimaryMember(); if (primaryMember == null) { continue; } TypeInformation<?> propertyType = persistentProperty == null ? ClassTypeInformation.from(primaryMember.getRawType()) : persistentProperty.getTypeInformation(); TypeInformation<?> actualPropertyType = propertyType.getActualType(); Class<?> rawPropertyType = propertyType.getType(); JsonSchemaFormat format = configuration.getMetadataConfiguration().getSchemaFormatFor(rawPropertyType); ResourceDescription description = persistentProperty == null ? jackson.getFallbackDescription(metadata, definition) : getDescriptionFor(persistentProperty, metadata); JsonSchemaProperty property = getSchemaProperty(definition, propertyType, description); boolean isSyntheticProperty = persistentProperty == null; boolean isNotWritable = !isSyntheticProperty && !persistentProperty.isWritable(); boolean isJacksonReadOnly = !isSyntheticProperty && jackson.isReadOnly(persistentProperty); if (isSyntheticProperty || isNotWritable || isJacksonReadOnly) { property = property.withReadOnly(); } if (format != null) { // Types with explicitly registered format -> value object with format registrar.register(property.withFormat(format), actualPropertyType); continue; } Pattern pattern = configuration.getMetadataConfiguration().getPatternFor(rawPropertyType); if (pattern != null) { registrar.register(property.withPattern(pattern), actualPropertyType); continue; } if (jackson.isValueType()) { registrar.register(property.with(STRING_TYPE_INFORMATION), actualPropertyType); continue; } if (persistentProperty == null) { registrar.register(property, actualPropertyType); continue; } if (configuration.isLookupType(persistentProperty.getActualType())) { registrar.register(property.with(propertyType), actualPropertyType); } else if (associations.isLinkableAssociation(persistentProperty)) { registrar.register(property.asAssociation(), null); } else { if (persistentProperty.isEntity()) { if (!definitions.hasDefinitionFor(propertyType)) { definitions.addDefinition(propertyType, new Item(propertyType, getNestedPropertiesFor(persistentProperty, definitions))); } registrar.register(property.with(propertyType, Definitions.getReference(propertyType)), actualPropertyType); } else { registrar.register(property.with(propertyType), actualPropertyType); } } } return registrar.getProperties(); }
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;//ww w. j a v a 2s. c om 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); } } }
From source file:org.candlepin.swagger.CandlepinSwaggerModelConverter.java
private String getPropName(BeanPropertyDefinition propDef, String propName) { // hack to avoid clobbering properties with get/is names // it's ugly but gets around // https://github.com/swagger-api/swagger-core/issues/415 if (propDef.getPrimaryMember() != null) { java.lang.reflect.Member member = propDef.getPrimaryMember().getMember(); if (member != null) { String altName = member.getName(); if (altName != null) { final int length = altName.length(); for (String prefix : Arrays.asList("get", "is")) { final int offset = prefix.length(); if (altName.startsWith(prefix) && length > offset && !Character.isUpperCase(altName.charAt(offset))) { propName = altName; break; }//w w w .java2 s .c o m } } } } return propName; }