Hey guys. Does anybody know how I can define and use a method in a DTO? The DTO is proxied by Spring data projection (by a native query). It seems to not recognize my method I defined in the interface.
Copy code
Null return value from advice does not match primitive return type for: public abstract double <DTONAME>.<METHOD>()
r
Richard Gomez
08/21/2021, 9:18 PM
I suppose it depends on what the actual type of the proxied class is. Would an extension function work instead?
Copy code
fun MyDTO.myMethod() { }
d
Dirk
08/22/2021, 7:38 AM
Thanks for the reply @Richard Gomez. I want to use this method in a Freemarker template. And extension function become static methods in Java. So not really an option 😞
😔 1
Dirk
08/22/2021, 1:04 PM
Any other ideas?
r
Richard Gomez
08/23/2021, 4:30 PM
Another option would be creating a data class and defining a custom query + converter. Not as 'elegant' as an interface-based projection, but that should give you a concrete type that you can use methods on.
e.g.
Copy code
@ReadingConverter
class DtoNameConverter : Converter<Row, DtoName> {
override fun convert(row: Row): DtoName {
return DtoName(
id = row["id"] as Long,
...
)
}
}
d
Dirk
08/23/2021, 7:32 PM
I was already thinking about mapping the jrojected Interface manually to another class but that is definitely more elegant.
Thanks man, I really appreciated your help ❤️ 🙏