Using spring-data-mongodb-1.5.4
and mongodb-driver-3.4.2
I've a class Hotel
public class Hotel {
private String name;
private int pricePerNight;
private Address address;
private List<Review> reviews;
//getter, setter, default constructor, parameterized constructor
Review
class :
public class Review {
private int rating;
private String description;
private User user;
private boolean isApproved;
//getter, setter, default constructor, parameterized constructor
When I am calling Aggregation.unwind("reviews");
it throws
org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments
UnwindOperation unwindOperation = Aggregation.unwind("reviews");
Aggregation aggregation = Aggregation.newAggregation(unwindOperation);
AggregationResults<Hotel> results=mongoOperations.aggregate(aggregation,"hotel", Hotel.class);
I see this question but does't help me.
How to resolve this?
Document.class
orDBObject.class
for the aggregation output. Aggregations change the output shape by definition of what they are meant to do. Typically you just don't need a strict type for output, unless you really need some custom serialization. For everything else, just use the generics. That's what they are there for. – Golda