android5-6 Exercise 1: Setup and a first test ========================================== // Module build.gradle.kts (versions are placeholders) plugins { id("org.jetbrains.kotlin.plugin.serialization") version "" } dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:") } import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable data class RemoteNoteDto( val id: Long, val title: String, val body: String = "", // optional: has a default @SerialName("userId") val authorId: Long? = null // JSON key differs from the Kotlin name ) import kotlinx.serialization.json.Json // One shared instance, configured once val json = Json { ignoreUnknownKeys = true prettyPrint = true // only affects encoding } // app/src/test/.../RemoteNoteDtoTest.kt (a plain JVM test) class RemoteNoteDtoTest { @Test fun unknownKeysAreIgnored() { val text = "{\"id\":1,\"title\":\"Hi\",\"extra\":true}" val note = json.decodeFromString(text) assertEquals("Hi", note.title) assertEquals("", note.body) // the default was used } @Test(expected = SerializationException::class) fun missingRequiredFieldFails() { json.decodeFromString("{\"id\":1}") } } Imports for the test (check in the IDE): org.junit.Test, org.junit.Assert.assertEquals, kotlinx.serialization.SerializationException. Versions: the Kotlin plugin version must match your Kotlin version; the library version comes from the kotlinx.serialization releases page. Report what you used. Code unrun.