-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure Operations uses the supplied document class when creating BsonDocumentWrapper #1327
Conversation
…DocumentWrapper. JAVA-5349
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assumptions.assumeFalse; | ||
|
||
public abstract class AbstractMongoCollectionTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made abstract so that can test Operations changes via both sync and async paths
From the Jira ticket
Does the same problem happen with PojoCodec? |
Discriminators in the PojoCodec are configured by annotations so its most likely inherited with Pojos. |
I'm concerned this could have an unintended consequences on application code. It may be better to ensure that bson-kotlinx handles the lookup for polymorphic classes. |
How could bson-kotlinx fix this? The driver is now calling the serializer for the data class instead of for the interface/collection class, so it is the driver doing it wrong? It is now impossible to have a document collection that is polymorphic. Kotlinx would also need to know the interface to which to serialize to. So it is either the default behaviour change (as your fix is doing) or we need a way to provided the interface during write somehow (e.g. json encode requires the interface present to work json.encode(document). |
@robbamberg thanks again for the feedback :) I'm still considering the best way forward. I think the fix in this ticket is the correct and matches the probable original intent of the code. However, I'm trying to think if any user may rely on that current behaviour as it has been there with the driver for some time. PojoCodecs possibly the largest custom mappings inherit discriminator annotations so wouldn't be impacted and as such the risk may be small and worth fixing. For Kotlin there is also another ticket: JAVA-5338 - when using That could fix both usecases, however, it could easily break existing Also can you elaborate on the |
@rozza I can imagine you could want a Cat collection without the discriminator field, so breaking that flow feels risky for me as well. |
driver-sync/src/test/functional/com/mongodb/client/AbstractMongoCollectionTest.java
Outdated
Show resolved
Hide resolved
I tested this code fix with the Pojos and the PojoCodec and found that the behavior remains the same - although somethings surprised me and / or I had forgotten. Interface:
Findings:
Interface 2:
Findings:
Abstract
Findings:
Extends
Findings:
|
Good to know. Does this change anything about what we want to do with this PR, or suggest additional work that we should track going forward? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is good to merge then.
LGTM
JAVA-5349