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

fields as

"myResIdField": {"resName": "com.example.myapp:style/MyAppTheme", "resId": 123}

Example usage in with Json encoder:

val format = Json {
  prettyPrint = true
  ignoreUnknownKeys = true
  serializersModule = SerializersModule {
    contextual(AndroidResSerializer(context))
  }
}
...
format.encodeToString(objWithResIds)

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard
Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): Int
Link copied to clipboard
open override fun serialize(encoder: Encoder, value: Int)