65

I am trying to Parcelize a data class. It contains one parameter :

var tokenType: Any? = null

For this variable compiler complains at compile time that :

Type is not directly supported by Parcelize. 
Annotate the parameter with @RawValue if you want it to be serialized via 
writeValue()

Though the error is self-explanatory, when I add @RawValue like this:

@RawValue var tokenType: Any? = null

it gives an error :

This annotation is not applicable to the target value parameter

Any hints on how to handle this?

Marie
  • 194
  • 6
Tarun Deep Attri
  • 8,174
  • 8
  • 41
  • 56

1 Answers1

163

I got the answer to this problem from Kotlang community. Answer is you can not annotate the variable itself but you have to annotate its type.

So annotating in the following way removes the error :

 var tokenType: @RawValue Any? = null

Though do not forget to write serilizer/deserializer for this property manually as it will not be done automatically.

starball
  • 20,030
  • 7
  • 43
  • 238
Tarun Deep Attri
  • 8,174
  • 8
  • 41
  • 56