Pagorn
Pagorn

Reputation: 612

How to custom mapping Firebase Datasnapshot with custom object

I have a key and value that key is reserved-word in java.

{
  class:"1/1"
}

How can I map the datasnapshot with custom class

CustomClass customClass = dataSnapshot.getValue(CustomClass.class);

CustomClass.java

public class CustomClass{
  private String class //can not use class or Class
}

Upvotes: 0

Views: 789

Answers (1)

nathaniel.camomot
nathaniel.camomot

Reputation: 280

Try using @PropertyName, which marks a field to be renamed when serialized.

public class Foo {

    @PropertyName("class")
    private String clazz;

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }
}

Upvotes: 1

Related Questions