diff --git a/core/src/main/java/org/sql2o/reflection/PojoMetadata.java b/core/src/main/java/org/sql2o/reflection/PojoMetadata.java index f67c6b88..16755f60 100644 --- a/core/src/main/java/org/sql2o/reflection/PojoMetadata.java +++ b/core/src/main/java/org/sql2o/reflection/PojoMetadata.java @@ -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) { @@ -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();