Spring-data-mongo unable to instantiate java.util.List using Constructor -


using spring-data-mongodb-1.5.4 , mongodb-driver-3.4.2

i've 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 calling aggregation.unwind("reviews"); throws

org.springframework.data.mapping.model.mappinginstantiationexception: failed instantiate java.util.list using constructor no_constructor arguments

unwindoperation unwindoperation = aggregation.unwind("reviews"); aggregation aggregation = aggregation.newaggregation(unwindoperation); aggregationresults<hotel> results=mongooperations.aggregate(aggregation,"hotel", hotel.class); 

i see this question does't me.

how resolve this?

when $unwind reviews field, query's return json structure not match hotelclass anymore. because $unwindoperation makes reviews sub object instead of list. if try query in robomongo or other tools, can see return object

{   "_id" : objectid("59b519d72f9e340bcc830cb3"),   "id" : "59b23c39c70ff63135f76b14",   "name" : "signature",   "reviews" : {     "id" : 1,     "username" : "salman",     "rating" : 8,     "approved" : true   } } 

so should use class instead of hotellike unwindedhotel

public class unwindedhotel {      private string name;     private int pricepernight;     private address address;     private review reviews; }  unwindoperation unwindoperation = aggregation.unwind("reviews"); aggregation aggregation = aggregation.newaggregation(unwindoperation); aggregationresults<unwindedhotel> results=mongooperations.aggregate(aggregation,"hotel", unwindedhotel.class); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -