Skip to content

Period conversion does not support a ChronoUnit of WEEKS but supports weeks in ISO-8601 (e.g. P2W) and simple (e.g. 2w) formats #22225

@AlexFalappa

Description

@AlexFalappa

It may be worth adding to the documentation (chapter 2.8.8) that ChronoUnit.WEEKS is not supported in @PeriodUnit annotation to specify how to interpret unqualified integer values for Period configuration properties fields.

Specifying weeks fails with a root cause of:

...
Caused by: java.lang.IllegalArgumentException: '2' is not a valid simple period
	at org.springframework.boot.convert.PeriodStyle$1.parse(PeriodStyle.java:59) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.StringToPeriodConverter.convert(StringToPeriodConverter.java:65) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.StringToPeriodConverter.convert(StringToPeriodConverter.java:50) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41) ~[spring-core-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	... 57 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported unit Weeks
	at org.springframework.boot.convert.PeriodStyle$Unit.fromChronoUnit(PeriodStyle.java:273) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	at org.springframework.boot.convert.PeriodStyle$1.parse(PeriodStyle.java:47) ~[spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE]
	... 60 common frames omitted

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions