'kotlin java.lang.ClassCastException: class java.lang.String cannot be cast to class enum

So when I do only

  println(user.role.permissions)

I get this: [ALL]

But when I do

 println(user.role.permissions.stream().map {it}.collect(Collectors.toList()))

or try to call any method of permissions(ArrayList)

I get this error

 java.lang.ClassCastException: class java.lang.String cannot be cast to class com.example.demo.models.Permission (java.lang.String is in module java.base of loader 'bootstrap'; com.example.demo.models.Permission is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader

Role entity

@Entity
@Table(name="role")
@TypeDefs(TypeDef(name = "jsonb", typeClass = JsonBinaryType::class))
class Role {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long? = null
    @Column(name="name", unique = true, nullable = false)
    lateinit var name: String
    @Type(type = "jsonb")
    @Column(name="permissions", columnDefinition = "jsonb", nullable = false)
    var permissions: List<Permission> = ArrayList()
}

Liquibase migration

<changeSet id="1" author="liquibase">
    <createTable tableName="role">
        <column name="id" type="BIGINT" autoIncrement="true">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="name" type="varchar(100)">
            <constraints nullable="false" unique="true"/>
        </column>
        <column name="permissions" type="jsonb" defaultValue="[]">
            <constraints nullable="false"/>
        </column>
</changeSet>

Permission enum

enum class Permission() {
    ALL
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source