Skip to content

Generic Firestore @Exclude fields are not actually excluded in Kotlin #5621

@dorianpavetic

Description

@dorianpavetic

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository.
If you have a general question, need help debugging, or fall into some
other category use one of these other channels:

  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

Link to my Stackoverflow question: https://stackoverflow.com/questions/77739613/kotlin-multiple-setters-getters-generics#comment137055437_77739613

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 31
  • Firebase Component: Firestore
  • Component version: firebase-bom:32.7.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

While trying to save data to Firestore, it still saves my 'details' field, even though annotated with @Exclude.
Problem occurs because Kotlin generates bridge getters/setters my generic data class with Object instead of only with my provided generic type. There are double getters/setter, where original ones are indeed annotated with @Exclude, but synthetic ones are not. Should Firestore object mapper take that into account in some way, or are there any ways to bypass this limitation ?

Relevant Code:

RoomV2.kt

data class RoomV2(	... ) : DetailableModel<RoomDetails> { /** Firestore constructor only */ constructor() : this(...) @set:com.google.firebase.firestore.Exclude @get:com.google.firebase.firestore.Exclude override var details: RoomDetails? = null ... }

and my DetailableModel with generic parameter:

interface DetailableModel<TDetailsModel> { var details: TDetailsModel? }

I have decompiled RoomV2 class and it results in:

... @com.google.firebase.firestore.Exclude @Nullable public RoomDetails getDetails() { return this.details; } // $FF: synthetic method // $FF: bridge method public Object getDetails() { return this.getDetails(); } @com.google.firebase.firestore.Exclude public void setDetails(@Nullable RoomDetails var1) { this.details = var1; } // $FF: synthetic method // $FF: bridge method public void setDetails(Object var1) { this.setDetails((RoomDetails)var1); } ...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions