You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
pkubowicz
changed the title
Inconsistent nullability of read() in templates
Inconsistent nullability of read() in templates: not sure if mapper can skip a document
May 14, 2021
While EntityReader should never return null, there are possibilities where a Converter might return null as Spring's Converter may return null.
In Kotlin, the compiler won't allow writing an implementation returning null.
Actually, Kotlin suggests the right thing to do.
I am looking for a way to ignore invalid documents and return remaining ones.
Spring Data actually never intended to support skipping results, it happened more by accident. I'd suggest registering a lifecycle listener that allows you to update the document prior to mapping it.
We decided to revisit the mentioned code paths and to remove code paths that allow for null as a result of EntityReader. Thanks for making us aware of this.
In spring-data-mongodb 3.1.8 ReactiveMongoTemplate.ReadDocumentCallback#doWith includes code to deal with null:
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
, sosource
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.
The text was updated successfully, but these errors were encountered: