I want to use auto-value with firebase 9.2.0+. I have the following code:
@AutoValue
public abstract class Office {
public static Builder builder() {
return new AutoValue_Office.Builder();
}
public abstract double latitud();
public abstract double longitud();
@AutoValue.Builder
public static abstract class Builder {
public abstract Builder latitud(double latitud);
public abstract Builder longitud(double longitud);
public abstract Office build();
}
}
But when I make to call this Office office = childDataSnapshot.getValue(Office.class);
I am getting this error:
com.google.firebase.database.DatabaseException: No properties to serialize found on class com.example.app.model.Office
Somebody have an idea why I am getting this error and how to solve it? I read that firebase is no longer using jackson
for json serialization. So I am not sure how to specify a kind of @JsonProperty("latitud")
I have used @PropertyName
unsuccessfully.
I also tried rename the abstract methods like public abstract double getLatitud();
and after that the error is the next one:
java.lang.InstantiationException: Can't instantiate abstract class com.example.app.model.Office
So I am not sure how to solve this.
SOLUTION
Thanks to hatboysam and Frank van Puffelen I finally could face this problem with the next solution.
- I created a FirebaseUtil enum with two methods for serialize and deserialize objects for Firebase based on hatboysam answer and Frank van Puffelen comment.
- I create a couple of
User
andPhone
classes for testing. Dependencies:
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.0' compile 'com.fasterxml.jackson.core:jackson-databind:2.8.0'
Usage example:
User user = FirebaseUtil.deserialize(dataSnapshot, User.class); Map<String, Object> map = FirebaseUtil.serialize(user);