I'm new in using Firebase and Android. I have a project to save an order and a payment in one child and show them all in adapter. But it show error when get data with postSnapshot
from model class. I dont know where the fault in my project. Error like this:
com.firebase.client.FirebaseException: Failed to bounce to type
and
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "payment"
My firebase structure looks like:
And then this is my java code:
MainActivity.java
String status = "orderSucces";
Firebase ref = new Firebase("https://myfirebase-d8a8a.firebaseio.com/order");
orderID = "-Kxi37Ro2oCPxQkb5L5u";
Query query = ref.child(status).orderByChild("orderID").equalTo(orderID);
query.addValueEventListener(new com.firebase.client.ValueEventListener() {
@Override
public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
progressBar.setVisibility(View.VISIBLE);
if (dataSnapshot.exists()) {
for (com.firebase.client.DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
OrderModel data = postSnapshot.getValue(OrderModel.class);
orderModel.add(data);
adapter = new Adapter(getApplication(), orderModel);
//adding adapter to recyclerview
recyclerView.setAdapter(adapter);
progressBar.setVisibility(View.GONE);
}
} else {
progressBar.setVisibility(View.GONE);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
OrderModel.java
public class PemesananModel implements Serializable {
public String orderID, paymentID, buyerName, buyerPhone, paymentMethod;
PemesananModel() {}
public PemesananModel(String orderID, String paymentID, String buyerName, String buyerPhone, String paymentMethod) {
this.orderID = orderID;
this.paymentID = paymentID;
this.buyerName = buyerName;
this.buyerPhone = buyerPhone;
this.paymentMethod = paymentMethod;
}
public String getOrderID() {
return orderID;
}
public void setOrderID(String orderID) {
this.orderID = orderID;
}
public String getPaymentID() {
return paymentID;
}
public void setPaymentID(String paymentID) {
this.paymentID = paymentID;
}
public String getBuyerName() {
return buyerName;
}
public void setBuyerName(String buyerName) {
this.buyerName = buyerName;
}
public String getBuyerPhone() {
return buyerPhone;
}
public void setBuyerPhone(String buyerPhone) {
this.buyerPhone = buyerPhone;
}
public String getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(String paymentMethod) {
this.paymentMethod = paymentMethod;
}
}