How to ignore new fields for an object model with Firebase 1.0.2

后端 未结 4 736
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 18:50

I\'m using the last version at the moment of Firebase dependency, which is 1.0.2 and I\'m having problems into getting my pojos parsed correctly.

The thing is, at an

相关标签:
4条回答
  • 2020-12-15 19:21

    As the accepted answer states, Firebase now uses Jackson, so you can annotate the desired methods you wish to ignore with

    @JsonIgnore

    Edit:

    Firebase changed everything. Woot. Now use this instead:

    @Exclude

    0 讨论(0)
  • 2020-12-15 19:22

    Firebase 1.0.3 was released and now uses Jackson 2.2.2, so annotation @JsonIgnore is the way to go.

    Edit: as of now in 2017, Firebase doesn't use Jackson anymore. the correct annotation is @Exclude.

    0 讨论(0)
  • 2020-12-15 19:25

    Update:

    As others pointed, annotation @Exclude is right way to use it now. But if you use Kotlin that won't work. For Kotlin use

    @get:Exclude var data: String? = nil
    //or
    @set:Exclude var data: String? = nil
    //or both
    @set:Exclude @get:Exclude var data: String? = nil
    

    Because annotation can be applied only for generated fields and not to properties.

    Old answer:

    I'm coming to Firebase from GSON were I used transient keyword. And that works with Firebase too

    public transient String data;
    
    0 讨论(0)
  • 2020-12-15 19:46

    For those who have moved over to Google's official version of Firebase (As of May 29, 2016), you can use @Exclude instead of @JsonIgnore or @JsonProperty. Here is the link to their document.

    Example:

    public class dataPacket{
        public String data;
        ...
        @Exclude
        public String getData(){return data;}
    }
    
    0 讨论(0)
提交回复
热议问题