3

I push data to Firebase using Order object, the question is I want the first letter of every child name capital. I defined the property like "Complain" but in Firebase it still shows as "complain", I dont know how to make it.

The current structure of the Firebase:

The current structure of the Firebase

The structure I want:

The structure I want

I defined the property like this:

@Data
public class Order implements Serializable {

@SerializedName("Complain")
private String Complain;

public Order() {
 Complain = "";
}

public String getComplain() {
    return Complain;
}

public void setComplain(String complain) {
    Complain = complain;
}
}

I push data to Firebase like this:

Map<String, Object> map = new HashMap<>();
map.put(orderSavePath, order);
reference.updateChildren(map).addOnCompleteListener(listener);
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
kate
  • 79
  • 1
  • 9

1 Answers1

6

The Firebase JSON serialization name is controlled by the annotation PropertyName.

public class Order implements Serializable {

    private String Complain;

    public Order() {
     Complain = "";
    }

    @PropertyName("Complain")
    public String getComplain() {
        return Complain;
    }

    @PropertyName("Complain")
    public void setComplain(String complain) {
        Complain = complain;
    }

}

The annotation needs to be on both the getter and the setter. Alternatively you can just use public fields and reduce the class to:

public class Order {
    @PropertyName("Complain")
    public String Complain;
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807