0

I am sending information to a website using volley and receiving a json response, I try to send this response to my firebase database but it crashes with the error : com.google.firebase.database.DatabaseException: No properties to serialize found on class org.json.JSONObject

This is my code

 private FirebaseDatabase sushFirebaseDatabase;
 private DatabaseReference tbbbbbb;
 ..... 
   Request.Method.POST,burl, jsonobject,
   new Response.Listener<JSONObject>() {
       @Override
        public void onResponse(JSONObject response) {
           FirebaseUser user = mAuth.getCurrentUser();
           String userID = user.getUid();
           mAuth = FirebaseAuth.getInstance();

           sushFirebaseDatabase=FirebaseDatabase.getInstance();

           tbbbbbbb=sushFirebaseDatabase.getReference(Respons_Path);
           tbbbbbbb.child(userID).push().setValue(response);

Please help

Anas Mehar
  • 2,739
  • 14
  • 25
Yayayaya
  • 216
  • 3
  • 13

2 Answers2

1

You have to create a POJO (Plain old Java Object) class and serialized your JSONObject to that POJO. Then Firebase can handle this.

To create POJO class you have to ensure:

  1. Either all your required variables are Public
  2. Or implement getter/setter for each required variables
  3. Or implement proper public constructor to create object.

You can find Plethora of Options here to convert JSONObject to Class object.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46
0

To anyone who would encounter the same problem, the simplest way is to save it to the database as a string, like this

   ........... 
   tbbbbbbb.child(userID).push().setValue(String.valueOf(response));
Yayayaya
  • 216
  • 3
  • 13