1

database structure image

I getting this error say

com.google.firebase.database.DatabaseException: Expected a Map while deserializing, but got a class java.util.ArrayList

I try some solution from solution1 solution2 and more, plus some googling for hours but i didn't get any working solution.

so please anyone can help me to understanding this firebase structure database structure image and its solution.

here is my sample code

category object class

public class Category {
    private String link;
    private String categoryName;
    private String activeJob;
    private Map<String, JobList> jobList;

    ....

    public Map<String, JobList> getJobList() {
        return jobList;
    }

    public void setJobList(Map<String, JobList> jobList) {
        this.jobList = jobList;
    }
}

Job list object class

public class JobList {
    private String employerName;
    private String jobClosingDate;
    private String jobCode;
    private String jobTitle;
    private String jobLink;
    private String status;
    private String updatedDate;

at MainActivity

public void getJobListFromFirebase() {
        ChildEventListener childEventListener = new ChildEventListener() {
            @Override
            public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

                categories = dataSnapshot.getValue(Category.class);
            }
            @Override
            public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            }
            .......

2 Answers 2

3

Change your category class to this:

    private String link;
    private String categoryName;
    private String activeJob;
    private List<JobList> jobList;

    ....

    public List<JobList> getJobList() {
        return jobList;
    }

    public void setJobList(List<JobList> jobList) {
        this.jobList = jobList;
    }
}

from your database structure, either we can do something like List<JobList> or Map<Int,JobList> (not Map<String,JobList>). try this and let me know.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much it working : ) can you please tell me why it work with list and not arrayList?
arrayList will also work... but not map<string,JobList>
0

change Map of jobList to List of joblist in Category model class

public class Category {
    private String link;
    private String categoryName;
    private String activeJob;
    private List<JobList> jobList;

    ....

    public List<JobList> getJobList() {
        return jobList;
    }

    public void setJobList(List<JobList> jobList) {
        this.jobList = jobList;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.