Skip to content

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

@jberger

Description

@jberger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions