dooor
dooor

Reputation: 61

Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments ]

i am getting

Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments ] with root cause
org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

this exception while updating the mongodb nested document.

the problem is the same as it is dicscuseed it this link

http://forum.spring.io/forum/spring-projects/data/nosql/724397-mapping-exception-with-mongodb-aggregation-framework

but still no clue how to solve it. anyone gone thorugh this??

Upvotes: 4

Views: 19098

Answers (2)

Ak S
Ak S

Reputation: 93

change to as below it should work

String _id;

SomeObject objectList;

Upvotes: 1

Daniel S.
Daniel S.

Reputation: 830

I just had the same problem and solved it thanks to: Mongo db java unwind operation in aggregate query throwing exception

When in the aggregation the unwind happened, the results are flattened so in my case I had a class like:

MyClass {
   String _id;
   List<SomeObject> objectList;
}

The exception occurs because of the flattening, the results on my list object instead of coming up in an array, now are just a single object because of the $unwind.

What I did to fix this was to create the same class without the list:

MyClassAggregationResult {
  String _id;
  SomeObject objectList;
}

This way the results are mapped correctly.

Hope this works for you as well.

Upvotes: 8

Related Questions