-
Notifications
You must be signed in to change notification settings - Fork 123
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
Trimming of input string upon conversion to Class, boolean or numeric types #181
Conversation
this.function = function; | ||
} | ||
|
||
public T convert(final String value) { | ||
return function.convert(value); | ||
final String cleanValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a ternary operator instead? Then a new variable doesn't need to be allocated
} | ||
|
||
Object writeReplace() { | ||
return new Ser(id); | ||
} | ||
} | ||
|
||
enum StringCleanup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that using an Enum vs a Boolean means we can easily expand the behavior in the future.
But I wonder whether we would need anything here beyond "trim" and "don't trim". Can you think of any string manipulation other than trim we might need in the future? If not, I'd lean towards just using a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might even make more sense to wrap the converter with a TrimmingConverter
which could be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a cool idea, then it can be easily added/removed from converters by us, and used separately by others if desired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It overlaps with another change I was doing so I'll send a single PR which supercedes this one. /cc @yrodiere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #185. I borrowed a commit from this PR.
Superseded by #185, which fixes everything I was trying to fix. Closing. |
As discussed here.
I did not add trimming to the built-in converters for
String
,Character
, orInetAddress
, since that seemed dangerous.I did not add any kind of warning when leading/trailing whitespaces are detected. Let me know if you want that, too.
Note that some types were already handling leading/trailing whitespaces correctly (
Double.parse
andFloat.parse
trim the string before parsing, in particular), but most did not (Integer
, ...).Please do not merge yet as @dmlloyd is preparing a large pull request. Just let me know when his PR is merged, I will rebase mine.