Making JSON Functional
We already used a library to render and parse Kotlin objects in JSON in the database chapter. It worked, but it was not an ideal solution, so we’ll do something better now.
Let’s consider what the problems are with that solution:
-
It’s based on reflection; changing the name of one of our classes would break the database layer.
-
It’s based on exceptions; we trap them but it’s not ideal.
-
It does not handle Kotlin sealed classes, so we had to write and register our own serializers or use annotations.
So let’s see how we could design an ideal functional JSON library. At the end of the day what we want is to be able to serialize objects of a given type into a JSON string and be able to parse them back. We can translate this into ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access