Hi folks, when i serialize manually in json the ou...
# serialization
g
Hi folks, when i serialize manually in json the outcome produces escaped chars:
Copy code
"data": "{\"imahubKey\":\"eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpbWFodWIiLCJzdWIiOiJ0ZXN0NTIxMDEiLCJleHAiOjE2NDY4MzM2MzIsImlhdCI6MTY0NjgyMzYzMn0.5L6T1-8EkzR41IX2V43ImI1hfBrIMEJEXXTr88FD8QbST82-l4_kg31tjA0xph_LgvUGPuMtXsRhfx44WgvcAA\"}"
This is my serializer:
Copy code
public fun SharedPayload.encodeToJson(): JsonElement = SharedPayloadJson.encodeToJsonElement(
    SharedSharedPayloadFromBuilder.serializer(), this as SharedSharedPayloadFromBuilder
How can i disable the escaping when im dealing with strings?
n
i guess you want to have data be json inside the
SharedPayload
try making that not a string but a
JsonLiteral
or more specifically a
JsonObject
then it will serialize like you want
g
Hi nikky, thanks for the info!. I am trying to make it work with type Any for data, do you think im better of with jsobject or should i stick with generics? FYI my motivasion to work with any type is to make it work also with other types (e.g. proto). On second thought maybe is it ok for me to store everything as jsonObjects then serialize my
sharedpayload
as i wish, for example either to jsonElement or either to Proto?
n
Stick to JsonElement at least
If you also use proto or cbor, maybe you need Any and somehow the serializer its using, but that gets very complicated quickly
g
indeed that's the case, it got very complicated 😛 thanks for help though, appreciate it