Repository navigation
Replies: 1 comment 6 replies
|
I'd much prefer just adding specific StreamWriteConstraints instead a catch all 'use the StreamReadConstraints' when writing. |
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi there,
I'm a maintainer of JobRunr, an open-source library for background job processing. JobRunr provides a Jackson integration for job serialization, which is used by most of our users.
I'd like to propose an improvement to address the asymmetry between string serialization and deserialization constraints in Jackson.
The issue
We've received multiple bug reports from users encountering exceptions such as:
See, for example, jobrunr/jobrunr#1403 and jobrunr/jobrunr#1515.
As a library, there is little we can do to prevent this from happening. Users may introduce large strings anywhere in a job's arguments or exception messages and stack traces. More importantly, the serialization library, in this case, Jackson, has complete control over how job arguments are serialized.
The main problem is that Jackson allows a string to be serialized even when its length exceeds the configured maximum for deserialization, only to reject that same string when it is subsequently read back.
This asymmetry is difficult for applications to reason about, particularly when they rely on Jackson for both serialization and deserialization. It can result in data being successfully serialized but then rejected during deserialization with the same Jackson configuration.
Suggested improvement
Our current workaround would be to implement a custom StringSerializer that rejects strings exceeding the configured
StreamReadConstraints.getMaxStringLength()limit. However, this duplicates logic that Jackson could provide out of the box, and any application facing the same issue would need to implement a similar workaround.I'd like to propose adding an option to enforce read constraints during serialization as well. For example:
When enabled, this feature would ensure that strings exceeding the configured deserialization limit are rejected during serialization, preventing Jackson from producing JSON that it would subsequently refuse to deserialize under the same constraints.
For our use case, we would enable this feature by default in JobRunr.
An alternative approach would be to introduce corresponding limits in StreamWriteConstraints, ideally with defaults that align with StreamReadConstraints. This would make it possible to configure serialization and deserialization limits independently when necessary, while avoiding unexpected incompatibilities by default.
This would be useful to us in 2.x, as well as 3.x. Would you consider adding something like this? Or any other suggestions on how to deal with this?
Thanks for your time and for maintaining Jackson!
All reactions