Let’s say we have a third-party class that we are using as a type in one of our data class that we want to be serialized, then we have to write a custom serializable for
@Serializable to work.
Now the most straightforward way to go forward is to write a custom object that extends
KSerializer of type
And then use this along with the existing annotation like
But let's say our third party class contains values that are non-primitive or are in a form that we don’t want to serialize, we can write a
surrogate class to act as intermediate before encoding and decoding.
In this case, we write a Serializer for the surrogate class instead of the actual class.
And use this class as the serializer instead. Et voila
This is a simple way to mock runtime dependencies in Instrumentation tests when using Koin Library
First, let’s take a look at how an application would mostly be set up when using Koin for DI.