Custom serialisation
Borrowing the example from Gson's TypeAdapter
, we will create a Point
class that can revive strings like "5,8"
. Let's see how the reviver looks like:
Note: a third path
argument is forwarded by the built-in revivers, mostly to help display more informative error messages when necessary. JSON.parse(..., reviver)
would not forward a path as it is not part of the native API.
With that, we are ready to create our Point
class:
We can now use it as follows:
Last updated