aaberg / sql2o

sql2o is a small library, which makes it easy to convert the result of your sql-statements into objects. No resultset hacking required. Kind of like an orm, but without the sql-generation capabilities. Supports named parameters.
http://sql2o.org
MIT License
1.14k stars 229 forks source link

In v1.7.0, kotlin data class is no longer recognized as pojo #373

Open yusukezzz opened 2 months ago

yusukezzz commented 2 months ago

My english is very poor, sorry.

Thank you for making great library!

I recently upgraded to v1.8.0 from v1.6.0 and noticed that the code that used kotlin data class as pojo stopped working. This change seems to have occurred since v1.7.0.

sample project

Data Class Definition

data class User(val id: Int, val name: String)

v1.6.0 outputs

[User(id=1, name=foo), User(id=2, name=bar)]

but in v1.7.0

Exception in thread "main" org.sql2o.Sql2oException: Could not find parameter-less constructor of class class org.example.User
    at org.sql2o.reflection.ReflectionObjectConstructorFactory.newConstructor(ReflectionObjectConstructorFactory.java:24)
    at org.sql2o.reflection.FactoryFacade.newConstructor(FactoryFacade.java:80)
    at org.sql2o.reflection.PojoMetadata.initializePropertyInfo(PojoMetadata.java:99)
    at org.sql2o.reflection.PojoMetadata$Cache.evaluate(PojoMetadata.java:244)
    at org.sql2o.reflection.PojoMetadata$Cache.evaluate(PojoMetadata.java:241)
    at org.sql2o.tools.AbstractCache.get(AbstractCache.java:49)
    at org.sql2o.reflection.PojoMetadata.getPropertyInfoThroughCache(PojoMetadata.java:81)
    at org.sql2o.reflection.PojoMetadata.<init>(PojoMetadata.java:68)
    at org.sql2o.DefaultResultSetHandlerFactoryBuilder.newFactory(DefaultResultSetHandlerFactoryBuilder.java:61)
    at org.sql2o.Query.newResultSetHandlerFactory(Query.java:539)
    at org.sql2o.Query.executeAndFetch(Query.java:585)
    at org.example.MainKt.main(Main.kt:32)
    at org.example.MainKt.main(Main.kt)

Kotlin's data class is very useful and I want to use it as a POJO as before, is it possible to fix this behavior...?

aaberg commented 2 months ago

Hi @yusukezzz,

Thanks for reporting this. I need to investigate the issue, and then I will get back to you.

And, by the way, I think your English is quite good🙂