JAVA-3815: Pojo Codec - Detect property models on extended interfaces #563
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If we have an interface like:
which is implemented as:
and has a concrete implementation that's called
SampleImplementorImpl
.When
PojoBuilderHelper
goes to create the property models, it only checksfor methods on the current class and super classes - not interfaces. In
the above example, this means the property model will only have "third" entry -
no "first" or "second" property model. Today, you can manually get around that by
creating a @BsonCreator by hand:
The presence of the
@BsonProperty
on the@BsonCreator
method willcreate the property models. Conversely though, if you want to leverage a
Convention
implementation to dynamically create aInstanceCreator
that knows how to find
SampleImplementorImpl
above, you won't be ableto.
InstanceCreator
is only provided properties for whichPropertyModel
exists, so above, sincePojoBuilderHelper
didn'tdiscover the interface fields, and there is no exposed API to add
property models, your
InstanceCreator
will never be provided thefirst
andsecond
fields present on the interface.Simply put, if you provide the pojo codec a class that is not concrete,
extends an interface for methods, and does not have a
@BsonCreator
annotation, there is no way to implement a
InstanceCreator
implementation that works for the non concrete class. You get stuck in
a place where the class can serialize since the concrete implementation
SampleImplementorImpl
is provided at runtime, but then you have no wayto deserialize it since usages in the code only reference
SampleImplementor
.We've worked around this problem for years and created 700+ hand written
@BsonCreator
annotations, so at this point I want to fix actual the problem.This fix is relatively straight forward: Update
PojoBuilderHelper
toscan implementing classes and interfaces, which provides a fully
populated property model.
JAVA-3815