terpal-sql icon indicating copy to clipboard operation
terpal-sql copied to clipboard

I cannot get Postgres `enum` to deserialize properly to an `enum class` in Kotlin

Open cies opened this issue 1 month ago • 0 comments

I have a user_notification_preferences table with a profile_type column of type profile_type_enum not null. The profile_type_enum type is defined as:

create type profile_type_enum as enum ('Admin', 'Retailer', 'Supplier');

When trying to deserialize a result containing the profile_type column to a data class' val profileType: ProfileType property, where the ProfileType enum class is defined as:

    @Serializable
    enum class ProfileType {
      Admin, Retailer, Supplier
    }

I get the following error:

	Caused by: java.lang.IllegalArgumentException: Unsupported kind: ENUM at column:ColumnInfo(name=profile_type, type=profile_type_enum)
            RowDecoder.kt:364   	io.exoquery.sql.RowDecoder.decodeBestEffortFromDescriptor
            RowDecoder.kt:309   	io.exoquery.sql.RowDecoder.decodeNullableSerializableElement
            RowDecoder.kt:386   	io.exoquery.sql.RowDecoder.decodeSerializableElement
            UserNotificationPreferences.kt:26    db.dto.UserNotificationPreferencesWithType$$serializer.deserialize

This brings me to believe that enums are not supported yet.

My current workaround is:

  • cast it to text in the sql query
  • deserilize it to String
  • then doe some manual ProfileType.valueOf(it) to get the enum in Kotlin

Maybe I'm doing something wrong, maybe emun deserialization is simply not implemented yet.

cies avatar Nov 15 '25 12:11 cies