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

13,633

Solution 1

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.

Solution 2

change to as below it should work

String _id;

SomeObject objectList;

Share:
13,633
dooor
Author by

dooor

Updated on June 28, 2022

Comments