Michal Janos
10/25/2021, 10:27 PMencodeToString
of double in json for js (multiplatform) with trailing zeros?
In our case, we have test json with double format (with trailing zeros), we use decodeFromString
and than encodeToString
and compare it.
For JVM it is allright, but in JS output is without trailing zeros.rnett
10/25/2021, 11:38 PMMichal Janos
10/26/2021, 12:29 AM@Test
fun testDecodeEncode() {
val jsonTestData = "{\"foo\":0.0,\"bar\":1.25}"
val testItemData: TestItem =
Json.decodeFromString(
jsonTestData
)
assertEquals(jsonTestData, Json.encodeToString(testItemData))
}
@Serializable
data class TestItem(
val foo: Double,
val bar: Double,
)
What is OK for JVM, but for JS:
AssertionError: Expected <{"foo":0.0,"bar":1.25}>, actual <{"foo":0,"bar":1.25}>.
ephemient
10/26/2021, 5:43 AMJoffrey
10/26/2021, 12:39 PM0
be a problem in the JSON as opposed to 0.0
?Michal Janos
10/26/2021, 12:59 PM