Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetched field name using PropertyDescriptor to fix fields with upper … #2752

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.amazonaws.services.dynamodbv2.datamodeling.StandardAnnotationMaps.TableMap;
import com.amazonaws.util.StringUtils;

import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -199,9 +201,13 @@ static final class BeanMap<T,V> extends LinkedHashMap<String,Bean<T,V>> {
}

private void putAll(Class<T> clazz, boolean inherited) {
PropertyDescriptor[] propertyDescriptors = null;
try {
propertyDescriptors = Introspector.getBeanInfo(clazz).getPropertyDescriptors();
} catch (final Exception no) {}
for (final Method method : clazz.getMethods()) {
if (canMap(method, inherited)) {
final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, null);
final FieldMap<V> annotations = StandardAnnotationMaps.<V>of(method, getFieldNameForMethod(propertyDescriptors, method));
if (!annotations.ignored()) {
final Reflect<T,V> reflect = new MethodReflect<T,V>(method);
putOrFlatten(annotations, reflect, method);
Expand All @@ -210,6 +216,18 @@ private void putAll(Class<T> clazz, boolean inherited) {
}
}

private String getFieldNameForMethod(PropertyDescriptor[] propertyDescriptors, Method method) {
String defaultName = null;
for (PropertyDescriptor propertyDescriptor : propertyDescriptors)
{
if(method.equals(propertyDescriptor.getWriteMethod()) || method.equals(propertyDescriptor.getReadMethod()))
{
defaultName = propertyDescriptor.getName();
}
}
return defaultName;
}

private void putOrFlatten(FieldMap<V> annotations, Reflect<T,V> reflect, Method getter) {
if (annotations.flattened()) {
flatten((Class<T>)annotations.targetType(), annotations.attributes(), (Reflect<T,T>)reflect);
Expand Down