-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Extending BuilderBasedDeserializer #1869
Comments
Right, I wouldn't expect Beyond this I am ok removing Other possibility could be to just instead approach this by cut-n-pasting existing builder based deserializer (which extends |
Thanks for the prompt reply! Caveat understood and I think we'll assume the risk. I think the best entry point for us is removing the The I've submitted a patch along these lines. Please let me know if I've missed something. |
Since PR was merged, I think I can close this issue. New issues to be created for new changes, ideas, additional work. |
We have a thread local builder implementation to try and reduce the impact of builder instances on the garbage collector. Much of our builder usage is through Jackson, and thus we are writing a BeanDeserializerModifier with the goal of extending the BuilderBasedDeserializer.
Ideally, we would like to reuse most of the existing functionality but the class is proving somewhat difficult to extend. First, the
Object deserialize(JsonParser p, DeserializationContext ctxt)
method is declared final (as are a few others). This prevents us from subclassing and overriding the method. Other methods cannot be delegated/overridden because they areprotected
orprivate
(e.g._deserializeUsingPropertyBased
andvanillaDeserialize
) -- however, we can work around the protected ones by placing our class in the same package.Our code provides a build method which accepts builder class and a consumer of an instance of that builder. This encapsulates the lifecycle of the builder into the consumer and allows the code to re-use builder instances (such builder instances are required to have a
reset
method which is invoked automatically before the builder is consumed). Retrofitting the code into Jackson was not too bad for the vanilla case.First, we replace the first branch in
public final Object deserialize(JsonParser p, DeserializationContext ctxt)
:And here's our
vanillaDeserializeAndFinishBuild
implementation which mostlyvanillaDeserialize
fromBuilderBaseDeserializer
but also includes our build logic and thus skips thefinishBuild
call:We are using Jackson
2.9.2
and it looks like the method isfinal
in master as well. No real issue here, I think we can work around it. Mostly, wanted to point out our use case and enquire as to whether you had any tips for extendingBuilderBasedDeserializer
and whether some of the restrictions could be lifted in the future. If not, any help understanding what pitfalls you see that led to restricting those methods could help us structure our code better. Finally, we're open to contributing some code to make the class more extensible, but didn't want to presume what direction you had in mind so any tips in this regard are welcome as well.The text was updated successfully, but these errors were encountered: