This repository demonstrates pitfalls with Micronaut 3.6.0 properties mapping when
using java.time.LocalDate
properties in application.yml
.
Described problems has been raised as Micronaut issue #7863.
See also YAML timestamp specification.
Tests use following properties class
@ConfigurationProperties("jcw")
@Data
@Introspected
public class Config {
LocalDate localDateProperty;
List<DatesListItem> dates;
@Builder
@Data
@Introspected
public static class DatesListItem {
private String id;
private String stringDate;
private Date javaUtilDate;
private LocalDate localDate;
}
}
Example config
jcw:
local-date-property: 2022-01-01
Test that demonstrates the issue LocalDateAsYamlDateTest.
Problem 2: LocalDate property expressed as YAML string reports that Unable to convert value [2022-01-01] to target type [LocalDate] due to: Text '2022-01-01' could not be parsed at index 4
Example config
jcw:
local-date-property: '2022-01-01'
Test that demonstrates the issue LocalDateAsYamlStringTest.
Problem 3: List elements containing LocalDate
property specified as YAML date are silently discarded
Example config
jcw:
dates:
- id: stringDate
stringDate: 2022-01-01
- id: javaUtilDate
javaUtilDate: 2022-01-01
# below entry is not mapped by micronaut because local date is specified as yaml timestamp
# see https://yaml.org/type/timestamp.html
- id: localDateAsDate
localDate: 2022-01-01
- id: localDateAsString
localDate: '2022-01-01'
-
Test that demonstrates the issue DatesOnListTest#shouldContainLocalDateExpressedAsDateInYaml .