72

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?

0

1 Answer 1

178

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.

9
  • 6
    After seeing this answer I immediately realised understood what target annotation meant, thank you!
    – wax911
    Commented Dec 17, 2018 at 9:16
  • 11
    How do you write the serilizer/deserializer for the Any type?
    – Beast77
    Commented Oct 13, 2019 at 6:46
  • 1
    @Tarun why would you use Parcelize for then?
    – frapeti
    Commented Oct 27, 2019 at 3:40
  • 1
    still working...many thanks Commented Sep 30, 2021 at 8:52
  • 3
    Though do not forget to write serilizer/deserializer for this property manually as it will not be done automatically. - what do you mean exactly?
    – user924
    Commented Dec 23, 2023 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.