1

I'm trying to convert a kotlin dataclass to a JsonElement, is there a way to do it using kotlin?

@Serializable
data class SubjectContext(
    val name: String,
    var programContext: Properties? = null
)

@Serializable
data class Properties(
    val color: String,
    var large: Int
)

C.Meza
  • 11
  • 3
  • Why don't use `Gson`? – CoolMind Mar 08 '22 at 21:38
  • Take a look at the `kotlinx.serialization` docs: https://kotlinlang.org/docs/serialization.html#example-json-serialization `Json.encodeToString(Properties("red", 2))` should do the trick – Spitzbueb Mar 09 '22 at 09:10

0 Answers0