https://kotlinlang.org logo
#serialization
Title
# serialization
e

Eric O'Connell

09/29/2023, 9:47 PM
Hello… I am using what I'd call an imperative approach to serializing JSON, that is, by mapping datatypes to
JsonObject
,
JsonPrimitive
, etc. However, in doing so I am taking kotlin values that are natively representable in JSON (e.g.,
Float
) and then converting them to strings (in construction of
JsonPrimitive
), and then transforming them back to strings, which ends up calling
toDoubleOrNull()
… given that this data represents large lists of 2d coordinates, I am seeing times in excess of 185ms for relatively small documents on Android devices. My main question: is there a way to avoid this double-conversion penalty so I can go directly from kotlin -> json string?