1

The documentation for all the setValue() methods of DatabaseReference states:

In addition, you can set instances of your own class into this location, provided they satisfy the following constraints:

  1. The class must have a default constructor that takes no arguments
  2. The class must define public getters for the properties to be assigned.

Properties without a public getter will be set to their default value when an instance is deserialized.

The model classes defined in the QuickStart sample project do not have getter methods defined. My experiments seem to indicate they are not actually needed. I'm able to successfully store and retrieve instances of classes that have no getter methods defined, just public fields. Is the documentation correct?

koceeng
  • 2,169
  • 3
  • 16
  • 37
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158

1 Answers1

4

Firebaser here

The Firebase Database SDK for Android will serialize/deserialize properties based on either:

  • JavaBean-like getters/setters
  • public fields

I'll add a note that we should document that second type too.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807