PojoMetadata can't introspect getters correctly

31 views
Skip to first unread message

adam.r...@gmail.com

unread,
Nov 8, 2016, 12:20:14 PM11/8/16
to sql2o
https://github.com/aaberg/sql2o/blob/master/core/src/main/java/org/sql2o/reflection/PojoMetadata.java

private PropertyAndFieldInfo initializePropertyInfo() {
<SNIP>
// prepare methods. Methods will override fields, if both exists.
for (Method m : theClass.getDeclaredMethods()) {
if (m.getParameterTypes().length!=1) continue;

if (m.getName().startsWith("get")) {

---

since Getters always have a parameter types length of zero, this method skips parsing the getters. 

Since the converter determination logic uses the getter to determine the type converter to use, if you do not have defined fields, they can't be mapped. addColumnMapping doesn't help in this circumstance.

I discovered this when I attempted to use a wrapper object that had a delegate object with the fields and used JScience for unit conversion in the getters/setters. Since the wrapper object didn't have a distance field within it, only getters/setters that called the delegate, Sql2o wouldn't populate the column. It kept telling me "Property with name 'distance' not found on class MyClass".

I believe this code should instead use "if (m.getParameterTypes().length >= 1) continue;"

adam.r...@gmail.com

unread,
Nov 8, 2016, 12:23:16 PM11/8/16
to sql2o, adam.r...@gmail.com
Reply all
Reply to author
Forward
0 new messages