Skip to content

Commit 38d36ab

Browse files
committed
Document how to add metadata for collection and enum default values
Closes gh-12874
1 parent 56c2a52 commit 38d36ab

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-configuration-metadata.adoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,51 @@ special handling for collection types (that is detected even if only a getter is
814814
The annotation processor also supports the use of the `@Data`, `@Getter`, and `@Setter`
815815
lombok annotations.
816816

817+
818+
The annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
819+
In the cases where a `Collection` or `Enum` property has a non-empty default value,
820+
<<configuration-metadata-additional-metadata,manual metadata>> should be provided.
821+
822+
Consider the following class:
823+
824+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
825+
----
826+
@ConfigurationProperties(prefix="rabbit")
827+
public class RabbitProperties {
828+
829+
private List<String> addresses = new ArrayList<>(Arrays.asList("a", "b")) ;
830+
831+
private ContainerType = ContainerType.SIMPLE;
832+
833+
// ... getter and setters
834+
835+
public enum ContainerType {
836+
837+
SIMPLE,
838+
839+
DIRECT
840+
841+
}
842+
843+
}
844+
----
845+
846+
In order to document default values for properties in the class above, you could add the following
847+
JSON to <<configuration-metadata-additional-metadata,the manual metadata of the module>>:
848+
849+
[source,json,indent=0]
850+
----
851+
{
852+
"name": "rabbit.addresses",
853+
"defaultValue": "a, b"
854+
},
855+
{
856+
"name": "rabbit.container-type",
857+
"defaultValue": "simple"
858+
}
859+
----
860+
861+
817862
[NOTE]
818863
====
819864
If you are using AspectJ in your project, you need to make sure that the annotation

0 commit comments

Comments
 (0)