If I'd like to map a jsonb column in exposed but d...
# exposed
p
If I'd like to map a jsonb column in exposed but don't want/cannot map it to a data class, can I use it somehow? Something like Map<String, Any?>?
Copy code
val data = jsonb<Map<String, JsonElement>>("data", Json.Default)
c
Hi @Pihentagy You should be able to use
json()/jsonb()
mapped to any type as long as you pass either a KSerializer or serialize/deserialize function pair, which is what Exposed uses to map the input value to/from the database. There's an example in the docs for Jackson that, while still using a data class, relies on custom serializer/deserializer to define the column mapping. I'm not sure exactly which
JsonElement
you're using, so I'll just leaves the bones here:
Copy code
val data = jsonb<Map<String, JsonElement>>(
    "data",
    serialize = {
        // Map to JSON string
    },
    deserialize = {
        // JSON String to Map
    }
)