-
Notifications
You must be signed in to change notification settings - Fork 973
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 support for creating regex and subnet-based ReadFrom instances from a single string #3016
Conversation
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.
Awesome, thanks for the contribution!
And thanks for the tests. I just have a few of notes.
return subnet(value.split(",")); | ||
} | ||
if (type.equalsIgnoreCase("regex")) { | ||
return regex(Pattern.compile(value)); |
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.
Possibly throws PatternSyntaxException
If we want to avoid expanding the contract (this is a runtime exception, but assuming existing applications could be catching the IllegalArgumentsException
it might constitute a breach of contract to them) we should perhaps wrap the PatternSyntaxException
inside a IllegalArgumentsException
? What do you think?
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 makes sense! My bad. fixed
Thank you, @tishun PR has been updated |
9a4c11b
to
d41760c
Compare
I didn't add support for the kebab-case format, but it might be worth considering. For instance, |
I'm not sure that What do you think, @wilkinsona? |
8d3d3d0
to
17f9b1f
Compare
In doubt, I suggest defaulting to non-order-sensitive to simplify the problem space. Once a future requirement comes along that asks for order-sensitive regex (the same could be for order-sensitive subnet) we can still sort that issue out later. For now, I suggest including the changes that fit in nicely and where we know that we like their design. |
Actually IMHO we should go with the kebab-case (only, without snake_case) instead.
|
@mp911de you were discussing if we should support order-sensitive pattern and not the case here, right? |
@tishun Even the initial request in Spring Boot expected the snake_case format: spring-projects/spring-boot#42576 (comment) |
Oh ... I see. Haven't considered that. But the enum conversion still makes sense to be honest - if another enum has these values (for some reason) we would simply convert based on the name (and not have to have another string representation in the alternative enum). Perhaps we need to support all three then. I will agree to both solutions (CamelCase + kebab-case and CamelCase + kebab-case + snake_case). |
Added support for all three formats. |
I read this comment spring-projects/spring-boot#42576 (comment) And actually, it makes sense. Initially, the scope of this PR was to support Adding additional formats like In Spring Boot it will be possible to use the following format:
So, I propose to revert everything that is related to format changes and just add support for Supporting order-sensitive regex has diverted me from my original focus. My apologies. UPDATE: I reverted the changes related to the formats. They can always be added later if necessary. |
…om a single string redis#3013 Before this commit, it was not possible to use ReadFrom.valueOf(name) for subnet and regex types. This commit introduces a new syntax subnet:192.168.0.0/16,2001:db8:abcd:0000::/52 and regex:.*region-1.* respectively
I agree. Thanks for working on this! |
Thank you very much, @tishun |
Closes #3013
Before this commit, it was not possible to use ReadFrom.valueOf for subnet and regex types. This commit introduces support for these types, as well as the use of names in underscore format