I am trying to read documents from a mongodb collection that contains a nested object. This nested object contains other objects, let’s call them cars.
In my java code, those cars are represented by an abstract class “Car”, with various different classes extending the car class. Furthermore the JSON object containing the Cars is represented by a Map<String, Car>.
If I read the object, a BeanInstantiationException is thrown, because Car is abstract. If i declare Car not abstract, the documents get read, but the Map contains a lot of cars with no specific values the inheriting classes would have (the Car class itself has no fields). I know that abstract classes can’t be instantiated, but every JSON object that gets read is of a type of an inheriting class, that is persisted in the attribute “_class” in the document in my DB.
mongoDB Version: 4.2.16
spring-data-mongodb Version: 3.2.3