4

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??

8
  • I've got no experience with mongodb but the mapper tried to instanciate a List which won't work because it is an interface. A workaround would be to convince your mapper to instead instantiate an ArrayList when List is needed. Commented Aug 3, 2017 at 13:49
  • Edit : actually, the issue in the thread you showed was that the query returned an Object instead of a single-element List, thus making the mapper fail to recognize an array. Is your issue the same ? Commented Aug 3, 2017 at 13:52
  • @JeremyGrand can you help me out to how to do it? Commented Aug 3, 2017 at 13:52
  • @JeremyGrand exaclty my issue Commented Aug 3, 2017 at 13:52
  • Its little vague without the code. Consider adding complete code including sample documents which when run will throw the exception Commented Aug 3, 2017 at 14:04

2 Answers 2

8

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.

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

Comments

1

change to as below it should work

String _id;

SomeObject objectList;

1 Comment

How can this work? we need a list of SomeObject, right? Aren't you changing the definition?

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.