Detect default enum value

This commit improves the configuration metadata annotation processor to
detect a default enum value. The algorithm is best-effort, similarly to
what it already does for well known prefixes (period, duration, etc).

Based on an expression and an identifier, the default value is inferred
if the expression matches the declaration of the property type.

See gh-7562
This commit is contained in:
Stéphane Nicoll
2024-08-01 13:19:34 +02:00
parent f4b4f4f0bf
commit 477bd7d15a
13 changed files with 233 additions and 50 deletions

View File

@@ -93,7 +93,7 @@ If you use `@ConfigurationProperties` with record class then record components'
The annotation processor applies a number of heuristics to extract the default value from the source model.
Default values have to be provided statically. In particular, do not refer to a constant defined in another class.
Also, the annotation processor cannot auto-detect default values for ``Enum``s and ``Collections``s.
Also, the annotation processor cannot auto-detect default values for ``Collections``s.
For cases where the default value could not be detected, xref:configuration-metadata/annotation-processor.adoc#appendix.configuration-metadata.annotation-processor.adding-additional-metadata[manual metadata] should be provided.
Consider the following example: