-
-
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
Distinguish null from empty string for UUID deserialization #2066
Comments
Ok. What do you think would make most sense for empty String in strict mode? Exception would seem like my first choice, although there is also the"empty" UUID, which you'd get from "all zeroes". It would also be possible to consider Now: from practical perspective, behavior change can not be made in 2.9 patch versions, since it would likely break some processing somewhere (even if behavior for default settings was unchanged, unless new feature was added, which in turn should not be done in a patch). |
I prefer to throw exception. All-zero UUIDs should be supplied explicitly, to be "strict". |
So: there is |
hi, new contributor :) can I try this one? |
@shahaf-sameach Absolutely! Trickiest part might just be figuring out how to get information on all parts of leniency settings: sources at To be more exact, there are 3 levels of leniency settings:
so the trick is to figure out combination of effective setting. An example can be found from @Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property)
throws JsonMappingException
{
final JsonFormat.Value format = findFormatOverrides(ctxt, property,
handledType());
if (format != null) {
...
} so you would add this method in And then finally, tests to verify that new handling works. Place to add tests would be
I hope this helps! |
I am thinking of actually tackling this as part of much bigger change -- #2728 -- and removing "good first issue" tag since approach I proposed here is not needed. |
I will start working on this issue, based on new |
So, implemented using new "CoercionConfigs" system; test To make coercion from empty String fail only for UUID, you can use: ObjectMapper mapper = ...;
mapper.coercionConfigFor(UUID.class)
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail); or to change handling of most similar scalar types: ObjectMapper mapper = ...;
mapper.coercionConfigFor(LogicalType.OtherScalar)
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail); or, even, if you really want, prevent it by most types (unless overridden by more-specific setting: ObjectMapper mapper = ...;
mapper.coercionConfigDefaults()
.setCoercion(CoercionInputShape.EmptyString, CoercionAction.Fail); Alternatively you can use |
For UUID deserialization, empty string is mapped to
null
by FromStringDeserializer. So something like{"parent_uuid": null}
can't be distinguished from{"parent_uuid": ""}
. From the view of a strict API, the latter is an error.It would be good to add some feature like "STRICT_STRING_VALUE", that FromStringDeserializer does not trim or shortcut empty strings so that UUID deserializer could report the error.
This may be an opposite feature of #768 ACCEPT_EMPTY_STRING_AS_NULL_OBJECT.
The text was updated successfully, but these errors were encountered: