Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New firebase json annotations

I'm using autovalue for my entities and annotated them to allow json parsing.

There are new annotations in the new sdk: Exclude, IgnoreExtraProperties, ThrowOnExtraProperties and @PropertyName: https://firebase.google.com/docs/reference/android/com/google/firebase/database/PropertyName. But PropertyName seems to be missing from the sdk..

like image 398
Vinay Nagaraj Avatar asked May 19 '16 17:05

Vinay Nagaraj


2 Answers

We missed the @PropertyName annotation in this release of the Firebase SDK for Android, but it was included in a release shortly after.

See this answer for a way to use Jackson explicitly with any version of the Firebase SDK: How to deserialise a subclass in Firebase using getValue(Subclass.class)

like image 151
Frank van Puffelen Avatar answered Sep 27 '22 18:09

Frank van Puffelen


BEFORE
@JsonIgnoreExtraProperties(ignoreUnknown=true)
public class ChatMessage {
   public String name;
   public String message;
   @JsonIgnore
   public String ignoreThisField;
}

dataSnapshot.getValue(ChatMessage.class)
AFTER
public class ChatMessage {
   public String name;
   public String message;
   @Exclude
   public String ignoreThisField;
}

dataSnapshot.getValue(ChatMessage.class)

Refer to https://firebase.google.com/support/guides/firebase-android#update_your_java_model_objects_numbered

like image 27
anton salim Avatar answered Sep 27 '22 18:09

anton salim