List<BeanPropertyDefinition> properties = beanDesc.findProperties(); for (BeanPropertyDefinition prop : properties) { if (StringUtils.isNotBlank(prop.getInternalName()) && prop.getInternalName().equals(propDef.getInternalName())) { if (prop instanceof POJOPropertyBuilder) { access = ((POJOPropertyBuilder) prop).findAccess();
/** * Returns all properties only known to Jackson. * * @return the names of all properties that are not known to Spring Data but appear in the Jackson metamodel. */ public Iterable<String> getSpringDataUnmappedProperties() { if (unmappedProperties.isEmpty()) { return Collections.emptySet(); } List<String> result = new ArrayList<String>(unmappedProperties.size()); for (BeanPropertyDefinition definitions : unmappedProperties) { result.add(definitions.getInternalName()); } return result; }
List<BeanPropertyDefinition> deserProperties = deserBeanDesc.findProperties(); for (BeanPropertyDefinition prop : deserProperties) { if (StringUtils.isNotBlank(prop.getInternalName()) && prop.getInternalName().equals(propDef.getInternalName())) { member = prop.getPrimaryMember(); break;
private static String[] getCodes(BeanPropertyDefinition property) { Assert.notNull(property, "BeanPropertyDefinition must not be null!"); Class<?> owner = property.getPrimaryMember().getDeclaringClass(); String propertyTitle = property.getInternalName().concat("._title"); String localName = owner.getSimpleName().concat(".").concat(propertyTitle); String fullName = owner.getName().concat(".").concat(propertyTitle); return new String[] { fullName, localName, propertyTitle }; } }
/** * Finds the {@link BeanPropertyDefinition} for the given {@link PersistentProperty} within the given definitions. * * @param property must not be {@literal null}. * @param definitions must not be {@literal null}. * @return */ private static BeanPropertyDefinition getDefinitionFor(PersistentProperty<?> property, Iterable<BeanPropertyDefinition> definitions) { for (BeanPropertyDefinition definition : definitions) { if (definition.getInternalName().equals(property.getName())) { return definition; } } return null; } }
/** * Returns the {@link PersistentProperty} for the property with the given final name (the name that it will be * rendered under eventually). * * @param finalName the output name the property will be rendered under. * @param entity the {@link PersistentEntity} to find the property on. * @param description the Jackson {@link BeanDescription}. * @return */ private Optional<? extends PersistentProperty<?>> findProperty(String finalName, PersistentEntity<?, ? extends PersistentProperty<?>> entity, BeanDescription description) { return description.findProperties().stream()// .filter(it -> it.getName().equals(finalName))// .findFirst().map(it -> entity.getPersistentProperty(it.getInternalName())); } }
/** * Creates a new {@link MappedProperties} instance for the given {@link PersistentEntity} and {@link BeanDescription}. * * @param entity must not be {@literal null}. * @param description must not be {@literal null}. */ private MappedProperties(PersistentEntity<?, ? extends PersistentProperty<?>> entity, BeanDescription description) { Assert.notNull(entity, "Entity must not be null!"); Assert.notNull(description, "BeanDescription must not be null!"); this.propertyToFieldName = new HashMap<PersistentProperty<?>, BeanPropertyDefinition>(); this.fieldNameToProperty = new HashMap<String, PersistentProperty<?>>(); this.unmappedProperties = new HashSet<BeanPropertyDefinition>(); for (BeanPropertyDefinition property : description.findProperties()) { if (description.getIgnoredPropertyNames().contains(property.getName())) { continue; } Optional<? extends PersistentProperty<?>> persistentProperty = // Optional.ofNullable(entity.getPersistentProperty(property.getInternalName())); persistentProperty.ifPresent(it -> { propertyToFieldName.put(it, property); fieldNameToProperty.put(property.getName(), it); }); if (!persistentProperty.isPresent()) { unmappedProperties.add(property); } } }
private List<BeanPropertyDefinition> getMappedProperties(PersistentEntity<?, ?> entity) { List<BeanPropertyDefinition> properties = getBeanDescription(entity.getType()).findProperties(); List<BeanPropertyDefinition> withInternalName = new ArrayList<BeanPropertyDefinition>(properties.size()); for (BeanPropertyDefinition property : properties) { Optionals.ifAllPresent(findAnnotatedMember(property), // Optional.ofNullable(entity.getPersistentProperty(property.getInternalName())), // (member, prop) -> withInternalName.add(property)); } return withInternalName; }
private Map<String, List<PersistentProperty<?>>> findUnwrappedPropertyPaths(Class<?> type, NameTransformer nameTransformer, boolean considerRegularProperties) { return persistentEntities.getPersistentEntity(type).map(entity -> { Map<String, List<PersistentProperty<?>>> mapping = new HashMap<String, List<PersistentProperty<?>>>(); for (BeanPropertyDefinition property : getMappedProperties(entity)) { Optionals.ifAllPresent(Optional.ofNullable(entity.getPersistentProperty(property.getInternalName())), // findAnnotatedMember(property), // (prop, member) -> { if (isJsonUnwrapped(member)) { mapping.putAll(findUnwrappedPropertyPaths(nameTransformer, member, prop)); } else if (considerRegularProperties) { mapping.put(nameTransformer.transform(property.getName()), Collections.<PersistentProperty<?>> singletonList(prop)); } }); } return mapping; }).orElse(Collections.emptyMap()); }
/** * Returns the fallback {@link ResourceDescription} to be used for the given {@link BeanPropertyDefinition}. * * @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); }
@Override public String apply(BeanPropertyDefinition input) { return input.getInternalName(); } };
@Override public String apply(BeanPropertyDefinition input) { return input.getInternalName(); } };
@Override public String apply(BeanPropertyDefinition input) { return input.getInternalName(); } };
@Override public boolean apply(BeanPropertyDefinition input) { return input.getInternalName().equals(propertyDefinition.getInternalName()); } };
@Override public boolean apply(BeanPropertyDefinition input) { return input.getInternalName().equals(propertyDefinition.getInternalName()); } };
@Override public boolean apply(BeanPropertyDefinition input) { return input.getInternalName().equals(propertyDefinition.getInternalName()); } };
.ofNullable(entity.getPersistentProperty(definition.getInternalName()));
/** * Returns all properties only known to Jackson. * * @return the names of all properties that are not known to Spring Data but appear in the Jackson metamodel. */ public Iterable<String> getSpringDataUnmappedProperties() { if (unmappedProperties.isEmpty()) { return Collections.emptySet(); } List<String> result = new ArrayList<String>(unmappedProperties.size()); for (BeanPropertyDefinition definitions : unmappedProperties) { result.add(definitions.getInternalName()); } return result; }
private static String[] getCodes(BeanPropertyDefinition property) { Assert.notNull(property, "BeanPropertyDefinition must not be null!"); Class<?> owner = property.getPrimaryMember().getDeclaringClass(); String propertyTitle = property.getInternalName().concat("._title"); String localName = owner.getSimpleName().concat(".").concat(propertyTitle); String fullName = owner.getName().concat(".").concat(propertyTitle); return new String[] { fullName, localName, propertyTitle }; } }
private List<BeanPropertyDefinition> getMappedProperties(PersistentEntity<?, ?> entity) { List<BeanPropertyDefinition> properties = getBeanDescription(entity.getType()).findProperties(); List<BeanPropertyDefinition> withInternalName = new ArrayList<BeanPropertyDefinition>(properties.size()); for (BeanPropertyDefinition property : properties) { Optionals.ifAllPresent(findAnnotatedMember(property), // Optional.ofNullable(entity.getPersistentProperty(property.getInternalName())), // (member, prop) -> withInternalName.add(property)); } return withInternalName; }