Image for post
Image for post
Image from -> https://proandroiddev.com/kotlin-education-d0b958740d6a

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 Timestamp

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

References
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#composite-serializer-via-surrogate
https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers


Image for post
Image for post
Image by Jibin Lawrance

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.

This code will not compile, this is only for a simple run through.

Now as an example, let’s take a look at some UI code that consumes these dependencies and for which we will write some Espresso tests.

In the above activity, HomeViewModel is lazy injected using an extension function provided by Koin. …


Image for post
Image for post
Image by Jibin Lawrance

Anyone working on Android development for a while would have come across this crash if they’ve written any fragment code

Jobin Lawrance

Senior Software Engineer @ Udaan, Recro

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store