1

I have the following data structure in my current Firebase real-time DB:

public class E {
  public int x;
  public int y;
  public int x;
}

This database is currently in use by my Android application which is already used by users in production.

I want to add a new member to the class (String z) as shown below:

public class E {
  public int x;
  public int y;
  public int x;
  public String z;
}

When using an old version of the app I see this error in logcat:

W/ClassMapper: No setter/field for z found on class com.me.you.E

And the application is stuck.

I have included a Database version check before the application starts to guide users to update their application, but was hoping not to need it in this specific case.

Is there any versioning possible on the data? Any other suggestion?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
CaptainNemo
  • 1,532
  • 2
  • 22
  • 45
  • Versioning is a difficult topic. There is no built-in versioning help with Realtime Database or Firestore. Your app needs to be able to handle possible changes, and that may involve not using built-in serialization. – Doug Stevenson Jun 29 '18 at 20:23
  • Can you elaborate or add any links to examples\articles\tutorials? – CaptainNemo Jun 29 '18 at 21:02

2 Answers2

1

I think you might not have added the getters and setters methods related to your new variable z.

Raj
  • 2,997
  • 2
  • 12
  • 30
  • That makes sense, but since I am seeing this error in the old version it is not relevant. the goal is not to update the old version while still allowing it to work ("Backward compatible") – CaptainNemo Jun 29 '18 at 19:48
  • This isn't the case - Firebase will use public fields directly in lieu of javabean style getters and setters. – Doug Stevenson Jun 29 '18 at 20:20
1

To get rid of that warning message, annotate your class with @IgnoreExtraProperties:

@IgnoreExtraProperties
public class E {
  public int x;
  public int y;
  public int x;
}

See the reference documentation for the IgnoreExtraProperties annotation:

Properties that don't map to class fields are ignored when serializing to a class annotated with this annotation.

As Doug commented, beyond this simple change to get rid of the warning, data migration on Firebase is a complex topic, which is impossible to answer in a single Stack Overflow question. But we can try to help with specific problems, such as warnings and crashes. If your application still gets stuck on loading, please post a minimal complete verifiable way to reproduce the problem.

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