Originally from the User Slack
@Leo_Urbina: I’m running into an issue with enum codecs. I have a Dao that has a method like the following
@Query(
"""SELECT * FROM deferred_tasks
WHERE trigger_id=:triggerId
AND status in :statuses
""",
)
fun getTasksForTriggerWithStatus(triggerId: UUID, statuses: List<DeferredTaskStatus>): PagingIterable<DeferredTask>
The issue is specifically with statuses
in the WHERE clause. I’ve registered the EnumCodec like so:
@Singleton
fun getSession(): CqlSession {
val enumCodec = ExtraTypeCodecs.enumNamesOf(DeferredTaskStatus::class.java)
return config.sessionBuilder.addTypeCodecs(
enumCodec,
TypeCodecs.listOf(enumCodec),
).build()
}
This seems to work fine as I’m able to insert data into the table. However when I try tu run getTasksForTriggerWithStatus
I get the following error:
com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [TEXT <-> ? extends com.sevenrooms.deferred.tasks.core.DeferredTaskStatus]
I assumed that the codec would take care of that, no?
Since I’m using the Enum names, I’m able to just map over the enums in the caller and search directly for the names, which works - but seems somewhat brittle
Any insight here would be helpful
Ok, figured it out - this is an issue with Kotlin and how it handles generics. I needed to use @JvmSuppressWildcards
to avoid it thinking of the List<DeferredTaskStatus
as a List<? extends DeferredTaskStatus
like so:
fun getTasksForTriggerWithStatus(triggerId: UUID, statuses: @JvmSuppressWildcards List<DeferredTaskStatus>): PagingIterable<DeferredTask>