Kotlinx.serialization part6

{"testName": "test", 
"testObject": {
"testSubName": "test2,
"testNumber": 123
}
}
@Serializable
data class JsonTest(val fruit: String, val rawJSON: JsonElement)
val jsonString = "{\"fruit\": \"apple\", \"rawJSON\": {\"number\": 48.321659646260812, \"text\": \"Hello\"}}"val result = jsonSerializer.decodeFromString<JsonTest>(jsonString)
@Serializable
data class JsonTest(val fruit: String, val rawJSON: JsonElement)
val jsonString = "{\"fruit\": \"apple\", \"rawJSON\": {\"number\": 48.321659646260812, \"text\": \"Hello\"}}"

val jsonSerializer = Json { }
val result = jsonSerializer.decodeFromString<JsonTest>(jsonString)
val text = jsonSerializer.encodeToJsonElement(result).toString()
val result2 = jsonSerializer.decodeFromString<JsonTest>(text)

Android developer @ Prezi

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Value Prediction in the Multi-core Era

REMOTE HIRE .NET DEVELOPER IN MIAMI

ANTHUS PC — Week 8— Term 3

About a postmortem.

Why You Should Use Python for Front-End Web Development

The Escape Button Is a Feature

Software Is Eating Management

ACME Certificates with LetsEncrypt and UltraDNS integration on Kubernetes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Peter Nagy

Peter Nagy

Android developer @ Prezi

More from Medium

Ideas and Solutions for Advent of Code 2021 in Kotlin — Part 2/4

Kotlin Multiplatform library with Kotest and Gradle Version Catalog

Achieving better baseline alignment for fonts in Jetpack Compose

Thymeleaf | Create dynamic hierarchy trees with Kotlin & Micronaut