question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Distinguish null from empty string for UUID deserialization

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Jun 10, 2020

So, implemented using new “CoercionConfigs” system; test CoerceMiscScalarsTest has full verification for UUID as well as other types. Default behavior in 2.12 NOT changed.

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 CoercionAction.AsNull to allow coercion to null, or, CoercionAction.AsEmpty to get “all-zeroes” UUID constructed.

1reaction
shahaf-sameachcommented, Apr 11, 2020

hi, new contributor 😃 can I try this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automaticaly convert empty strings to null in Java using JsonB ...
I encountered this problem on migration from Jackson to Jsonb where empty string value in request produces deserialization exception since it ...
Read more >
Uuid Library - 1.73.0
Distributed computing may use UUIDs to identify a remote procedure call. Transactions and classes involved in serialization may be identified by UUIDs.
Read more >
Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >
The Serializer Component (Symfony Docs)
The Serializer component allows you to serialize and deserialize these objects using a "discriminator class mapping". The discriminator is the field (in the ......
Read more >
How to Serialize Data With Django REST Framework
Django REST offers serialization and deserialization of data and above that it offers data ... avatar = CloudinaryField('image', blank=True, null=True).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found