art_tikal
art_tikal

Reputation: 3

Java, Spring Data. Mapping entity field of type Map of Lists

For the following entity mapping with Spring Data and Mongo DB :

@Document(collection = "candidates")
public class Candidate {
   private SortedMap<String, ? extends SortedMap<String, List<Expertise>>> expertises;
   ....
}

When loading the entity from the database the List< Expertise> becomes List< LinkedHashMap>. How can I specify the correct type of the object in the list?

Upvotes: 0

Views: 766

Answers (1)

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83051

That is a bug in our type resolution algorithm. We resolved the map value type of the outer map to Object, which drops all further generics information and thus no type information got written to the nested documents. This will cause only Maps being created on the reading side.

I've filed DATACMNS-440 for that and fixed it right away. The fix will be transitively included in the upcoming bugfix release (Spring Data MongoDB 1.3.4) early next week.

Still, I'd suggest you create dedicated types for the nested data structure as clients will have a hard time really knowing what this structure actually represents.

Upvotes: 2

Related Questions