Skip to content

Commit 660d284

Browse files
committed
Document when and how to use brackets when binding to maps
Closes spring-projectsgh-13506
1 parent 5623518 commit 660d284

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,24 @@ property name
11021102
TIP: We recommend that, when possible, properties are stored in lower-case kebab format,
11031103
such as `my.property-name=acme`.
11041104

1105+
When binding to `Map` properties, if the `key` contains anything other than lowercase
1106+
alpha-numeric characters or `-`, you need to use the bracket notation so that the original
1107+
value is preserved. If the key is not surrounded by `[]`, any characters that are not alpha-numeric
1108+
or `-` are removed. For example, consider binding the following properties to a `Map`:
1109+
1110+
[source,yaml,indent=0]
1111+
----
1112+
acme:
1113+
map:
1114+
"[/key1]": value1
1115+
"[/key2]": value2
1116+
/key3: value3
1117+
1118+
----
1119+
1120+
The properties above will bind to a `Map` with `/key1`, `/key2` and `key3` as the keys in the map.
1121+
1122+
11051123
[[boot-features-external-config-complex-type-merge]]
11061124
==== Merging Complex Types
11071125
When lists are configured in more than one place, overriding works by replacing the entire

0 commit comments

Comments
 (0)