Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@RawValue annotation is not applicable to target value parameter

Tags:

android

kotlin

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?

like image 385
Tarun Deep Attri Avatar asked Apr 02 '18 06:04

Tarun Deep Attri


1 Answers

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.

Hope it helps.

like image 192
Tarun Deep Attri Avatar answered Sep 23 '22 20:09

Tarun Deep Attri