-
-
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
Serializing Optional not enabled by default since 2.16.0 #4499
Comments
I found this was changed by #4082 |
@cor3000 Correct: this is the new intended behavior, and exception indicates the root cause. It is unfortunate issue referred does not fully explain logic (or have good title) to make it easier to find the change. But the goal was to prevent accidental serialization of So registering Java 8 types module is the fix, not workaround. Or, alternatively, registering custom serializer. |
Thank you, @cowtowncoder, for the clarification! Is there a way to avoid having to register the |
@schiemon if you mean "set some static thing to force all |
Yeah, globally (statically) setting such thing is not desirable and won't be in the future either. |
@cowtowncoder yes, this exactly what I had in mind. |
@schiemon I can see how that can be problematic. Unfortunately Jackson is so widely used by various frameworks and libraries that any global configuration (at Jackson level, not by application) is potential problem -- meaning that if global configuration existed, it would effect things users wouldn't plan to. So the choice of having no (*) globally configurable entries is conscious. (*) there are couple of things related to security (max name length) for which there are global static settings one can define as baseline -- but all overridable. |
Yeah, sorry to hear that. I don't know how gigantic you're talking about, but I have experience working with such systems as well. Somethings are better off modularized or isolated. But! Let's consider this as techincal debt we are willing to pay off :-) willing because it could be a sign that system getting bigger means ur business grew as well. Hopefully but there may be programming patterns/approaches to find! |
Thank you again for your detailed answers, @JooHyukKim and @cowtowncoder. I now have a much better understanding of the problem from your perspective as library maintainers. I do have one remaining question, though. Since it is closely related to the original question, I will ask it here. However, feel free to let me know if I should open a separate issue for this. Let’s say I register the Is there a way in the newer version to revert to the previous behavior to ensure that mappers are producing the same output? For instance, could something be configured at the mapper level to achieve this? This is getting long but I think the following is also important to mention in this context. I noticed a difference in behaviour between older versions when handling
When I am removing the visibility setting, both output the same string ( |
@schiemon I do not know why/how settings as applied in 2.12.x (which seem correct) would work differently in 2.13.x. These are relatively old versions by now so nothing much could be done to change them. But one possibility is that something in handling of "is-getter" ("isPresent()" etc) vs "regular getter" ("getValue()" etc) was not properly handled any longer; that is, visibility setting was not applied to "is-setters" and defaults were. Finally, while there is no centralized way to revert serialization of |
Also tests for attempts to serialize
|
A minor change in a test class was necessary; cf. FasterXML/jackson-databind#4499 Co-authored-by: Till-André Diegeler<[email protected]>
Search before asking
Describe the bug
in version 2.15.4 the following code below succeeded
giving the output
(Obviously this value doesn't make sense, but it doesn't fail with a hard exception, breaking existing projects)
when using version a higher version e.g. 2.17.0 the following Exception occurs instead (in both cases the jackson-datatype-jdk8.jar of the same version is on the classpath)
I didn't find this default behavior change in the release notes, so I wonder whether this is an intended change.
As a workaround I can register the Jdk8Module manually (commented out in the code above), to produce the same results as in 2.15.4
Version Information
2.17.0
Reproduction
Run the example using the maven dependencies
after switching to 2.16.0, 2.16.1, 2.17.0 the same code below fails
Expected behavior
giving the output as in 2.15.4, not throwing an exception
Additional context
even though we have a manual workaround it's difficult to track and adjust all usages by external libraries.
my apologies in case I missed the related documentation and this is the new expected behavior since 2.16.0
The text was updated successfully, but these errors were encountered: