Skip to content

Commit

Permalink
Issue aaberg#314: fix PojoMetadata to prefer more concrete getter/setter
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 21, 2019
1 parent b0c72df commit 379e7c1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/src/main/java/org/sql2o/reflection/PojoMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ private PropertyAndFieldInfo initializePropertyInfo() {
propertyName = propertyName.toLowerCase();
}

propertyGetters.put(propertyName, factoryFacade.newGetter(m));
final Getter existingGetter = propertyGetters.get(propertyName);
if (existingGetter != null && existingGetter.getType() != Object.class && m.getReturnType() == Object.class) {
// don't overwrite existing getter if it has more concrete type. See https://github.com/aaberg/sql2o/issues/314
// for more details.
} else {
propertyGetters.put(propertyName, factoryFacade.newGetter(m));
}
}

if (m.getName().startsWith("set") && m.getParameterTypes().length == 1) {
Expand All @@ -138,7 +144,13 @@ private PropertyAndFieldInfo initializePropertyInfo() {
propertyName = propertyName.toLowerCase();
}

propertySetters.put(propertyName, factoryFacade.newSetter(m));
final Setter existingSetter = propertySetters.get(propertyName);
if (existingSetter != null && existingSetter.getType() != Object.class && m.getParameterTypes()[0] == Object.class) {
// don't overwrite existing getter if it has more concrete type. See https://github.com/aaberg/sql2o/issues/314
// for more details.
} else {
propertySetters.put(propertyName, factoryFacade.newSetter(m));
}
}
}
theClass = theClass.getSuperclass();
Expand Down

0 comments on commit 379e7c1

Please sign in to comment.