Skip to content

Commit

Permalink
changed from function to value for encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
vextorspace committed Jul 1, 2024
1 parent cfa5cda commit 099e05c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions composeApp/src/commonMain/kotlin/model/Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ data class Item(var content: String = "New Item", val subItems: MutableList<Item
}

fun toJson(): String {
return encoder()
return encoder
.encodeToString(serializer(), this)
}

companion object {
fun encoder(): Json {
return Json { ignoreUnknownKeys = true }
}
val encoder = Json { ignoreUnknownKeys = true }

fun fromJson(itemJson: String): Item? {
return encoder()
.decodeFromString<Item?>(itemJson)
return encoder.decodeFromString<Item?>(itemJson)
}
}

Expand Down

0 comments on commit 099e05c

Please sign in to comment.