Description
In spring-data-mongodb 3.1.8 ReactiveMongoTemplate.ReadDocumentCallback#doWith includes code to deal with null:
T source = reader.read(type, document);
if (source != null) {
// …
}
return Mono.empty();
This code suggests that I can write a custom reader that returns null for elements that cannot be mapped and should be skipped.
However, this is not true. org.springframework.data.convert.EntityReader is not annotated with @Nullable
, so source
can never be null. In Kotlin, the compiler won't allow writing an implementation returning null.
Use case
By default it is impossible to use findAll
on a collection that contains one malformed document: mapping exception will crash the operation and no elements will be emitted. I am looking for a way to ignore invalid documents and return remaining ones.
If I am mistaken and there is a way to write a custom mapper that is able to skip documents that cannot be mapped, please let me know.