Mr.G
Mr.G

Reputation: 1275

Unexpected tokens (use ; to seperate expressions on the same line) in kotlin

I was using kotlin in my android project which is developing on java , I ve used kotlin data classes in my service layer

Now i wants to add alternate tag in serialied

@SerializedName(value="name", alternate={"person", "user"}) val title:String,

This gives me unexpected token issue and it seems its from kotlin side

This seems like kotlin issue can someone point me out issue

Upvotes: 3

Views: 4350

Answers (1)

Alex Romanov
Alex Romanov

Reputation: 11963

I assume this will do the job:

@SerializedName(value="name", alternate=arrayOf("person", "user")) val title:String

Kotlin compiler treats alternate={"person", "user"} as a function type.


EDIT by 1blustone:

In Kotlin 1.2 this is possible with array literals, but only in annotations:

@SerializedName(value = "name", alternate = ["person", "user"]) val title:String

Upvotes: 8

Related Questions