0

I have a Model which uses List of class objects. I am trying getvalue from datasnapshot of firebase query. But getting com.fasterxml.jackson.databind.JsonMappingException saying : Can not deserialize instance of java.util.ArrayList out of START_OBJECT token.

Code looks like this:

Key.java
@JsonIgnoreProperties(ignoreUnknown = true)
Class Key implements implements Parcelable {
    private String key;

     public Key() {
     }

     public String getkey() {
       return key;
     }

     public void setkey(String name) {
         this.key = name;
     }

     @Override
     public int describeContents() {
        return 0;
      }

      @Override
      public void writeToParcel(Parcel dest, int flags) {
         dest.writeString(this.key);
      }

      protected Key(Parcel in) {
         this.key = in.readString();
       }

      public static final Creator<Key> CREATOR = new Creator<Key>() {
          public Key createFromParcel(Parcel source) {
           return new Key(source);
       }

        public Key[] newArray(int size) {
           return new Key[size];
       }
     };       

}

Model.java
@JsonIgnoreProperties(ignoreUnknown = true)
Class Model implements implements Parcelable {
    private String Addr1;
    private String Addr2;
    private List<Key>Keys;

     public Model () {
     }

     public String getAddr1() {
       return this.Addr1;
     }
     public String getAddr2() {
       return this.Addr2;
     }

     public List<Key>getKeys(){
       return this.Keys;
     }

     public void setAddr1(String addr) {
       this.Addr1 = addr;
     }
     public void setAddr2(String addr) {
       this.Addr2 = addr;
     }

     public void setKeys(List<Key> keys){
       this.Keys = keys;
     }



     @Override
     public int describeContents() {
        return 0;
      }

      @Override
      public void writeToParcel(Parcel dest, int flags) {
         dest.writeString(this.Addr1);
         dest.writeString(this.Addr2);
         dest.writeTypedList(this.Keys);

      }

      protected Key(Parcel in) {
         this.Addr1= in.readString();
         this.Addr2 = in.readString();
         this.keys= in.createTypedArrayList(Keys.CREATOR);
       }

      public static final Creator<Model> CREATOR = new Creator<Model>() {
          public Key createFromParcel(Parcel source) {
           return new Model(source);
       }

        public Model[] newArray(int size) {
           return new Model[size];
       }
     };       

}

the object model is saved into Firebase DB. and In Firebase DB the Keys Structure looks like :

"Keys" : {
    "-KEr8rtIHAIAVftmRRAp" : {
      "key" : "-KEr8rquQnMzVycKlsGm"
    }
  },

In my view i am getting datasnapshot from firebase and trying to serialize Model class.

for (DataSnapshot data : dataSnapshot.getChildren()){
    Model cur= data.getValue(Model.class); 
}

while this call is made exception is thrown. I am newbie to Java serialization Please guide me through issue.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user954299
  • 195
  • 5
  • 15

1 Answers1

0

Solved it. I changed in the Model to HashMapkeys I realized the json structure later.

user954299
  • 195
  • 5
  • 15