Skip to content

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

@cies

Description

@cies

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions