Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
a017b890
Commit
a017b890
authored
Jan 10, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt field name in ValidationBindHandler to a valid ConfigurationPropertyName
Fixes gh-19580
parent
ccf4e1ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
DataObjectPropertyName.java
.../boot/context/properties/bind/DataObjectPropertyName.java
+3
-2
ValidationBindHandler.java
...ext/properties/bind/validation/ValidationBindHandler.java
+2
-1
ValidationBindHandlerTests.java
...roperties/bind/validation/ValidationBindHandlerTests.java
+35
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DataObjectPropertyName.java
View file @
a017b890
...
...
@@ -21,9 +21,10 @@ package org.springframework.boot.context.properties.bind;
*
* @author Phillip Webb
* @author Madhura Bhave
* @since 2.2.3
* @see DataObjectBinder
*/
abstract
class
DataObjectPropertyName
{
public
abstract
class
DataObjectPropertyName
{
private
DataObjectPropertyName
()
{
}
...
...
@@ -33,7 +34,7 @@ abstract class DataObjectPropertyName {
* @param name the source name
* @return the dashed from
*/
static
String
toDashedForm
(
String
name
)
{
public
static
String
toDashedForm
(
String
name
)
{
StringBuilder
result
=
new
StringBuilder
();
String
replaced
=
name
.
replace
(
'_'
,
'-'
);
for
(
int
i
=
0
;
i
<
replaced
.
length
();
i
++)
{
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/validation/ValidationBindHandler.java
View file @
a017b890
...
...
@@ -28,6 +28,7 @@ import org.springframework.boot.context.properties.bind.AbstractBindHandler;
import
org.springframework.boot.context.properties.bind.BindContext
;
import
org.springframework.boot.context.properties.bind.BindHandler
;
import
org.springframework.boot.context.properties.bind.Bindable
;
import
org.springframework.boot.context.properties.bind.DataObjectPropertyName
;
import
org.springframework.boot.context.properties.source.ConfigurationProperty
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertyName
;
import
org.springframework.core.ResolvableType
;
...
...
@@ -187,7 +188,7 @@ public class ValidationBindHandler extends AbstractBindHandler {
}
private
ConfigurationPropertyName
getName
(
String
field
)
{
return
this
.
name
.
append
(
field
);
return
this
.
name
.
append
(
DataObjectPropertyName
.
toDashedForm
(
field
)
);
}
ValidationErrors
getValidationErrors
()
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/validation/ValidationBindHandlerTests.java
View file @
a017b890
...
...
@@ -193,6 +193,14 @@ class ValidationBindHandlerTests {
.
satisfies
((
ex
)
->
assertThat
(
ex
.
getCause
()).
hasMessageContaining
(
"years"
));
}
@Test
void
validationErrorsForCamelCaseFieldsShouldContainRejectedValue
()
{
this
.
sources
.
add
(
new
MockConfigurationPropertySource
(
"foo.inner.person-age"
,
2
));
BindValidationException
cause
=
bindAndExpectValidationError
(()
->
this
.
binder
.
bind
(
ConfigurationPropertyName
.
of
(
"foo"
),
Bindable
.
of
(
ExampleCamelCase
.
class
),
this
.
handler
));
assertThat
(
cause
.
getMessage
()).
contains
(
"rejected value [2]"
);
}
private
BindValidationException
bindAndExpectValidationError
(
Runnable
action
)
{
try
{
action
.
run
();
...
...
@@ -305,6 +313,33 @@ class ValidationBindHandlerTests {
}
@Validated
static
class
ExampleCamelCase
{
@Valid
private
InnerProperties
inner
=
new
InnerProperties
();
InnerProperties
getInner
()
{
return
this
.
inner
;
}
static
class
InnerProperties
{
@Min
(
5
)
private
int
personAge
;
int
getPersonAge
()
{
return
this
.
personAge
;
}
void
setPersonAge
(
int
personAge
)
{
this
.
personAge
=
personAge
;
}
}
}
@Validated
static
class
ExampleValidatedBeanWithGetterException
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment