Skip to content

Commit

Permalink
Add mapping to a Map<String, ConfigObject> in the documentation
Browse files Browse the repository at this point in the history
(cherry picked from commit 0c4ab8c)
  • Loading branch information
arvind-vignesh authored and gsmet committed Mar 15, 2024
1 parent 3e19f04 commit 455ab13
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/src/main/asciidoc/config-mappings.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,39 @@ server.form.landing-page=index.html
The configuration property needs to specify an additional name to act as the key. In this case the `form()` `Map` will
contain three elements with the keys `login-page`, `error-page` and `landing-page`.

It also works for groups:
[source,java]
----
@ConfigMapping(prefix = "server")
public interface Servers {
@WithParentName
Map<String, Server> allServers();
}
public interface Server {
String host();
int port();
String login();
String error();
String landing();
}
----
.application.properties
[source,properties]
----
server."my-server".host=localhost
server."my-server".port=8080
server."my-server".login=login.html
server."my-server".error=error.html
server."my-server".landing=index.html
----
In this case the `allServers()` `Map` will
contain one `Server` element with the key `my-server`.

=== Defaults

The `@WithDefault` annotation allows to set a default property into a mapping (and prevent and error if the
Expand Down

0 comments on commit 455ab13

Please sign in to comment.