Hey guys. Does anybody know how I can define and u...
# spring
d
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
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
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
Any other ideas?
r
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
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 ❤️ 🙏
🙌 1