feat: add UUID string converter (#1017) - #1088
Open
zhanghuang090 wants to merge 1 commit into
Open
Conversation
| * Converts UUID values to canonical lowercase strings and reads strings using {@link UUID#fromString(String)}. | ||
| * Empty strings are treated as missing values, like blank cells. | ||
| */ | ||
| public class UuidStringConverter implements Converter<UUID> { |
Contributor
There was a problem hiding this comment.
The class name should remain UUIDStringConverter to stay consistent with Java’s standard java.util.UUID. There’s no need to use the Uuid variant.
| public UUID convertToJavaData( | ||
| ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { | ||
| String value = cellData.getStringValue(); | ||
| return value == null || value.isEmpty() ? null : UUID.fromString(value); |
Contributor
There was a problem hiding this comment.
To make the converter more robust, you might consider using StringUtils.isBlank(value) to handle null, empty, or whitespace-only strings, and then trim the value before parsing.
Something like UUID.fromString(value.trim()) would help avoid unexpected parsing failures caused by leading or trailing whitespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of the pull request
Related: #1017
Fields declared as
java.util.UUIDcurrently have no built-in converter. This adds UUID ↔ STRING conversion so identifiers can be imported and exported without a custom converter.Proposal: #1017 (comment)
What's changed?
UuidStringConverter, usingUUID.fromString()for non-empty input andUUID.toString()for canonical lowercase output. Empty strings are treated as missing values, consistently with blank cells.DefaultConverterLoader.ExcelDataConvertExceptionwith the parsing error as the cause.Validation
ClassUtilsFieldOverrideTestcleanup error (DirectoryNotEmptyExceptionwhile deleting a JUnit temporary directory on Windows). A focused rerun of that class plus UUID and loader tests passed all 27 cases without code changes.mvn -B -ntp -pl fesod-sheet -am -Dmaven.test.skip=false -Dtest=ClassUtilsFieldOverrideTest,UuidConverterTest,DefaultConverterLoaderTest -Dsurefire.failIfNoSpecifiedTests=false package spotless:checkpassed.javac --release 8against the built project classes.git diff --cached --checkpassed.Checklist