Skip to content
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

Do not automatically trim trailing whitespace from java.util.regex.Pattern values #3299

Closed
jberger opened this issue Oct 11, 2021 · 3 comments
Milestone

Comments

@jberger
Copy link

jberger commented Oct 11, 2021

Is your feature request related to a problem? Please describe.
I have a large JSON structure containing arrays of Patterns to match as part of a lookup. Some contain patterns that end in an escaped literal space, ie \\ . When this happens the trim behavior (that I had to search rather hard to find) causes the pattern to now end in an escape character which then fails to compile as a Pattern.

Describe the solution you'd like
While I can understand trimming string values in XML as an unfortunate side-effect of the whitespace independent structure, in JSON I would have expected to be somewhat more literal. Even so if this is the behavior that more people want, can you please at least add an attribute that would prevent trimming?

Usage example
Something like .with(DeserializationFeature.NO_TRIM) would be sufficient.

Additional context
I'm sure I must have missed something in the documentation but I was not easy to find that values were supposed to be trimmed. Indeed my searching mostly found people asking in various forums how to cause the values to be trimmed, not to prevent them from being trimmed. Clarifying that behavior in the documentation would be nice as well.

Thanks

@jberger jberger added the to-evaluate Issue that has been received but not yet evaluated label Oct 11, 2021
@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 11, 2021

(EDITED)

I can't promise I'll have time to work on this, but one thing that would help whoever had time to tackle this feature request would be to file a failing unit test showing expected behavior that is not occurring.
That is, case of giving what is deemed invalid input, and expecting an exception (which will not happen by default).
This would help also verify understanding of what is being asked.

Oh: I suspect there might already be a way to reconfigure new-ish "Coercion Config" setting -- by default it is rather permissive, but it may be possible to change that easily.
Given a test case this could be tested relatively easily.

@cowtowncoder cowtowncoder added 2.14 and removed to-evaluate Issue that has been received but not yet evaluated labels Oct 11, 2021
@cowtowncoder cowtowncoder changed the title Add option to not trim JSON string value before coercion Add option for FromStringDeserializer not to trim JSON string value when deserializing JDK types like java.util.regex.Pattern Oct 13, 2021
@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 13, 2021

Hmmmh. Looking at reference FromStringDeserializer, realized that I misunderstood the issue.
It is NOT about empty vs blank Strings (for which Coercion Config setting matters), but actual behavior for a set of "simple" JDK scalar types, as support from FromStringDeserializer.

This is both easier and more difficult thing since it is sort of irregular...

@jberger how about an alternative of specifically disabling trimming for Pattern (and if you can think of other JDK types handled for which similar issues might occur) instead? I understand the issue wrt trailing space, but I think it is in general dangerous for that type.

@cowtowncoder cowtowncoder added 2.13 and removed 2.14 labels Oct 24, 2021
@cowtowncoder
Copy link
Member

I think that an improvement to handling Patterns, specifically, would fit in 2.13(.1) patch, changing target.

@cowtowncoder cowtowncoder changed the title Add option for FromStringDeserializer not to trim JSON string value when deserializing JDK types like java.util.regex.Pattern Do not automatically trim trailing whitespace from java.util.regex.Pattern values Dec 5, 2021
@cowtowncoder cowtowncoder added this to the 2.13.1 milestone Dec 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants