0

I have a data structure in Firestore that looks like below:

enter image description here

The parent POJO is:

public class Restaurant {
    private Double distance;
    private GeoPoint geoPoint;
    private int distributionType;
    private List<DailyHours> dailyHours;


public Restaurant(Double distance, GeoPoint geoPoint, int distributionType, List<DailyHours> dailyHours) {

        this.distance = distance;
        this.geoPoint = restaurantLogo;
        this.restaurantDescription = distributionType;
        this.dailyHours = dailyHours;
}

// Getter & Setter (excluded most for the sake of clarity
public List<DailyHours> getDailyHours() {
        return dailyHours;
    }

    public void setDailyHours(List<DailyHours> dailyHours) {
        this.dailyHours = dailyHours;
    }
}

And then the DailyHours POJO:

public final class DailyHours {
    boolean selected;
    String thisDay;
    int startHour;
    int closeHour;

    public DailyHours(boolean selected, String thisDay, int startHour, int closeHour) {
        this.selected = selected;
        this.thisDay = thisDay;
        this.startHour = startHour;
        this.closeHour = closeHour;
    }
// Setter and Getter
}

How would I put this into an array (which would have an array within it)?

I am trying this (where restaurantArrayList is an array of Restaurant objects):

db.collection("database").get().addOnSuccessListener(queryDocumentSnapshots -> {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                Restaurant restaurant = documentSnapshot.toObject(Restaurant.class);
                restaurantArrayList.add(restaurant);
            }
}

and end up getting this error:

Could not deserialize object. Class com.eataway.partner.models.DailyHours does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped (found in field 'dailyHours.[0]')

I presume I have to parse through the array of objects but I have no idea how to do that. Please advise.

1 Answer 1

1

The error is telling you that Firestore requires that objects have a no-argument constructor to be able to instantiate objects for deserialization. A no-argument constructor is exactly what it sounds like:

public final class DailyHours {
    public DailyHours() {}

    // the rest of your class here
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry my knowledge of Java pales in comparison to yours :) . Thanks for pointing me in the right direction. That was all I needed to do.

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.