dave08
12/13/2022, 4:26 PMToshihiro Nakamura
12/14/2022, 11:16 AMdave08
12/14/2022, 11:32 AMenum Foo(val value: Int) { Bar(2), Baz(3) }
I need the value
property... maybe @KomapperEnum("value")
?Toshihiro Nakamura
12/14/2022, 12:29 PM@KomapperEnum(EnumType.FIRST_PARAM)
FIRST_PARAM means the first parameter of enum`s constructor.dave08
12/14/2022, 12:33 PMparamName
that default to an empty string and the EnumType.PARAMdave08
12/14/2022, 12:33 PMdave08
12/14/2022, 12:35 PMToshihiro Nakamura
12/14/2022, 1:23 PMdave08
12/14/2022, 1:25 PMFIRST_PARAM
is certainly better than nothing, but would be a bit limiting if these were actual domain classes...dave08
12/14/2022, 1:27 PM@JvmInline
value class FooWrapper(val value: Int) {
val status: Foo get() = Foo.values().first { it.value == value }
}
enum class Foo(val value: Int) {
Baz(2), Baz2(3), Bar(4);
}
Toshihiro Nakamura
12/14/2022, 2:00 PMabstract class Foo(val value: Int) {
object Baz: Foo(2)
object Baz2: Foo(3)
object Bar: Foo(4)
}
class FooTypeConverter : DataTypeConverter<Foo, Int> {
override val exteriorClass: KClass<Foo> = Foo::class
override val interiorClass: KClass<Int> = Int::class
override fun unwrap(exterior: Foo): Int {
return exterior.value
}
override fun wrap(interior: Int): Foo {
return when(interior) {
2 -> Foo.Baz
3 -> Foo.Baz2
4 -> Foo.Baz
else -> error("unknown: $interior")
}
}
}
@KomapperEntity
data class Person(@KomapperId val id: Int, val foo: Foo)
See also https://www.komapper.org/docs/reference/data-type/#data-type-conversiondave08
12/14/2022, 2:01 PMdave08
12/14/2022, 2:11 PMdave08
12/14/2022, 2:13 PMdave08
12/14/2022, 2:13 PMdave08
12/14/2022, 2:24 PMToshihiro Nakamura
12/14/2022, 2:29 PMIs that the right place?Yes. But, is there an extra space at the end of
org.komapper.core.spi.DataTypeConverter
?dave08
12/14/2022, 2:29 PMdave08
12/14/2022, 2:30 PMdave08
12/14/2022, 2:30 PMToshihiro Nakamura
12/14/2022, 2:31 PMdave08
12/14/2022, 2:33 PMwhen
in sealed class versiondave08
12/14/2022, 2:35 PMname
property and ignores my DataTypeConverter 🙈Toshihiro Nakamura
12/14/2022, 2:36 PMdave08
12/14/2022, 2:37 PM@KomapperEnum
annotation... maybe just treat it special WITH the annotation? (which is what I would have expected...)dave08
12/14/2022, 2:38 PMToshihiro Nakamura
12/14/2022, 2:39 PMdave08
12/14/2022, 2:40 PM