4

It would be perfect, if there was @IgnoreIfNull annotation for normalizing my db, But there is not so How should I handle if my data has null value in object class?

      public class Word {

               public String id;
               public String wordName;
               @IgnoreNull        //Origin may be null
               public String wordOrigin;
              }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
yardımcı Etis
  • 140
  • 2
  • 12

1 Answers1

2

The simplest solution would be to add the data as a Map and not as an object. In this way, you have more control over what properties you want to add. If you have properties with null values, simply don't add them to the Map.

This is available in Cloud Firestore. In the Firebase Realtime Database, there is no way you can have keys that can hold null values.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • this won't work if you are using the @ServerTimestamp which should be null – Yanay Hollander Aug 07 '20 at 05:27
  • @YanayHollander Hey Yanay! The ServerTimestamp should be `null` **only** when you are using a POJO class. In the case of a Map, you cannot pass `null` and expect a field to be populated with the ServerTimestamp. Please check my answer from this **[post](https://stackoverflow.com/questions/48474957/servertimestamp-is-always-null-on-firebase-firestore/48475027#48475027)**. – Alex Mamo Aug 07 '20 at 07:57