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?

2
  • 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. Commented Jun 29, 2018 at 20:23
  • Can you elaborate or add any links to examples\articles\tutorials? Commented Jun 29, 2018 at 21:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

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")
This isn't the case - Firebase will use public fields directly in lieu of javabean style getters and setters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.