https://kotlinlang.org logo
Title
d

dave08

01/18/2023, 12:13 PM
Is there an easy way to accomplish this (embedding raw json into the result -- maybe some annotation?):
@Serializable data class Foo(val bar: Int, val json: String)

val sample = Foo(1, """{"some": "json"}""")

val result = Json.encodeToString(sample)

// The result should be: { "bar": 1, "json": { "some": "json" } }
?
e

ephemient

01/18/2023, 12:15 PM
d

dave08

01/18/2023, 12:17 PM
So currently, I would just use
JsonElement
for the
json
field and it would work?
e

ephemient

01/18/2023, 12:18 PM
if you're ok with writing
Foo(
    bar = 1,
    json = buildJsonObject {
        put("some", "json")
    }
)
then yes, that currently works
d

dave08

01/18/2023, 12:20 PM
I have that on another layer, I was hoping not to expose it beyond there... but I guess I currently have no choice... but thanks for that issue... at least I know I'll be able to replace this in the near future 🙂!