I just discovered the kotlinx.serialization librar...
# serialization
j
I just discovered the kotlinx.serialization library and it seems to work very well and I can use it as a substitute for jackson, I wanted to do a little performance test and if I use it as the documentation says
val foo = Json.decodeFromString<Project>(string)
I see that the performance drops much more than others like jackson and GSON. instead, if I instantiate the serializer and then reuse it, the performance works much better,
val serializer = serializer(typeOf<Project>()) as KSerializer<Project>
val foo = Json.decodeFromString(serializer, string)
Is there a problem with doing it this way? more details in https://github.com/jcaromiq/serde-benchmark
h
It is not a problem, but using
serializer(typeOf())
results into a reflection like lookup at runtime to find the serializer. If you statically know the serializer, you could provide it
Json.decodeFromString(Project.serializer, string)
, which is faster without a runtime lookup.
e
if https://github.com/Kotlin/kotlinx.serialization/issues/1348 gets resolved, the difference should disappear. but for now, exactly what Phillip says
102 Views