Open jakobkmar opened 3 years ago
Thank you for reporting. The problem is that projection does not support (for now) type parameters for their root class.
As a workaround, I suggest to use a custom dedicated class for projection as specified in the doc https://litote.org/kmongo/extensions-overview/#projection . Look at the attached unit test.
Let's assume that I have a class called
Identifier
, and a serializer for that class calledIdentifierSerializer
, which serializes the Identifier to a String.Now inside of the class representing the documents of a collection, there is a field of the type
Identifier
, e.g.:Now I want to use
projection
in the following way:Now to the bug:
Somewhere inside of the
projection
call, there has to be an unsafe cast. BecausecurrentIdentifiers
is actually aList<String>
which it should not be - its type even isList<Identifier>
.Obviously, the custom serializer has not been used for deserialization of the returned array members in the database, instead
projection
did just return the actual raw content of the array in the database (which is the output of the serialize function of the custom serializer, which has been used correctly earlier on) and casted it to the desired type in an unsafe way.An example for what would fail now:
This of course fails, because
String
does not have a property callednamespace
.This should be fixed, because typesafety has been lost in this case.