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

Add new CoercionConfig system for customizing behavior of various coercions from secondary shapes #2728

Closed
cowtowncoder opened this issue May 19, 2020 · 1 comment

Comments

@cowtowncoder
Copy link
Member

One larger area of configurability where users have very different views of defaults is that of whether and when allow coercions from non-canonical shapes.

For example, some users would like following POJO:

public class Bean {
   public boolean value;
}

to be only readable from JSON like

{ "value" : true }

whereas others would want to accept

{ "value" : "true" }

or even

{"value" : 1 }

Agreeing on defaults is challenging, but historically Jackson has been using more permissive defaults due to user feedback (requests to allow alternate shapes to be accepted).
Conversely other users who prefer more rigid validation have requested ability to prevent coercions, resulting in things like:

  • MapperFeature.ALLOW_COERCION_OF_SCALARS (global setting) // originally just for primitive numebrs
  • @JsonFormat(lenient = false) // originally just for Date/Time
  • ConfigOverride mechanism for JsonFormat.Value

But while these can help a bit, there are issues like:

  • Global applicability (one size fits all)
  • No separation for different input shapes (everything allowed (very loose) or just primary (very strict))
  • Does not differentiate "empty" values either as input (do we allow "", { }, [ ]), or as result (Java [ ], new ArrayList<>(), new HashMap<>())

Given this, I am thinking of implementing configuration scheme that is modeled much like ConfigOverrides, but is more specialized with mapping combination of "target type"/"input shape" into resulting action (fail, coerce into null/empty/value).
Mapping of target type should allow both general type categories ("integral number", "POJO/Bean") and specific type/class (java.util.UUID) for convenience.
Target action has to be figured out since there is difference between mapping "empty" values (typically becomes null, "empty" or "fail") and "regular" values (real coercion from String "true" into boolean true, for example)

@cowtowncoder
Copy link
Member Author

Dup of #2113, close.

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

1 participant