-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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 Date and UUID deserialization support in nullSafeValue method #42956
Conversation
@minwoo1999 Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@minwoo1999 Thank you for signing the Contributor License Agreement! |
Thanks for the pull-request, but I'm not sure that we should make such a change. Currently the Can you provide a bit more background about the reasons behind these proposed changes? |
Thank you for your feedback! I think the intention behind the proposed changes to the nullSafeValue method is to allow it to handle Date and UUID types. While it currently focuses on basic JSON primitives, many developers frequently work with dates and UUIDs in JSON data and expect seamless support for these types. For instance, JSON APIs often use timestamps as milliseconds since the epoch, and being able to convert these directly into Date objects would simplify development. Similarly, since UUIDs are usually represented as strings, providing direct conversion would make working with them more convenient. Ultimately, the goal is to enhance flexibility and usability, enabling developers to manage commonly used data types directly within the nullSafeValue method, leading to cleaner code and a more efficient workflow. Thank you for considering this perspective! |
Thanks for the additional info @minwoo1999. I'm afraid I'm still not keen to merge this, but I do think you have a valid use-case so instead I've added a Date date = nullSafeValue(tree.get("date"), Integer.class, Date::new);
UUID uuid = nullSafeValue(tree.get("uuid"), String.class, UUID::fromString); |
This pull request introduces enhancements to the JsonObjectDeserializer class to support the deserialization of Date and UUID types.
Changes Made:
Added Support for Date:
Implemented logic to handle Date objects by converting a long timestamp from the JSON node to a Date instance.
java
Added Support for UUID:
Added functionality to convert a string representation of a UUID from the JSON node into a UUID instance.
java
New Unit Tests:
Implemented two unit tests to validate the new functionalities:
nullSafeValueWhenClassIsDateShouldReturnDate: Confirms that a JsonNode containing a timestamp correctly deserializes into a Date.
nullSafeValueWhenClassIsUUIDShouldReturnUUID: Validates that a JsonNode containing a UUID string deserializes into a UUID.
Benefits: These enhancements simplify the deserialization process by allowing the JsonObjectDeserializer to directly handle Date and UUID types, improving the usability of the class in applications that require these types.