I have a configuration property:
@ConfigurationProperties(prefix = "x.retention")
@Slf4j
@ConstructorBinding
@AllNonNullByDefault
@Validated
public class RetentionProperties {
private String isoPeriod;
}
isoPeriod is going to be a period in iso8061 format like P1M -> 1 month duration.
I want to check if the value has a correct format on Configuration Initialisation.
Can I somehow also manipulate the value on initialisation to transform it to Duration? like this
Duration duration = Duration.parse(isoPeriod);
So that I can directly use the Duration value and not validate it later in code?
Just change the type to
Duration, Spring Boot will convert it to the properDurationusing theStringToDurationConverter.Don't make it more complex then that.