I am working with a database where values are stored in an ARRAY
column which has the semantics of a Java Set
, most importantly that ordering does not matter.
Currently, the jOOQ generator generates POJOs and Records with Array<T>
type for those columns. This is problematic, because two arrays don't equal if their ordering is different.
I tried creating a custom converter, however, obviously defining the toType
as Set<String>::class.java
won't compile because of type erasure(?)
class ArrayToSetConverter() :
AbstractConverter<Array<String>, Set<String>>(Array<String>::class.java, Set<String>::class.java) { ... }
Compilation error:
Only classes are allowed on the left hand side of a class literal
Is there another way of achieving my goal?
Similar (unfortunately unanswered) question: jOOQ converter from String to List<MyType> in Kotlin
CodePudding user response:
With type erasure, I don't think you can formally create a Class<Set<String>>
type reference in neither Java nor kotlin. But you don't have to. Just do this:
class ArrayToSetConverter() : AbstractConverter<Array<String>, Set<String>>(
Array<String>::class.java,
Set::class.java as Class<Set<String>> // Unsafe cast here
) { ... }