AndroidResSerializer
Serializer that encodes Android Resource Id integer using AndroidResSurrogate.
When set as contextual
serializer it will encode
@Contextual val myResIdField: Int = com.example.myapp.R.style.MyAppTheme
Content copied to clipboard
fields as
"myResIdField": {"resName": "com.example.myapp:style/MyAppTheme", "resId": 123}
Content copied to clipboard
Example usage in with Json encoder:
val format = Json {
prettyPrint = true
ignoreUnknownKeys = true
serializersModule = SerializersModule {
contextual(AndroidResSerializer(context))
}
}
...
format.encodeToString(objWithResIds)
Content copied to clipboard