micronaut-core
micronaut-core copied to clipboard
More java.time support for yaml and converters
YAML has a defined timestamp type that is used when iso8601-like values are encountered, e.g. 2022-08-12. Unfortunately, snakeyaml parses them as java.util.Date by default (at UTC timezone). This patch adds a snakeyaml constructor that parses timestamps as the appropriate java.time type instead – LocalDate, LocalDateTime, or OffsetDateTime, depending on the actual input. To maintain compatibility, I added conversions from these types to Date. For ODT this is straight-forward, but for LD and LDT, it uses UTC as the offset to match the old snakeyaml behavior. This is a bit arbitrary, but required for compatibility. We could remove these conversions for Micronaut 4. I've also altered the existing time conversions to be able to handle ISO 8601 strings as inputs for conversion to the java.time types. This means that when a configuration property is defined with java.time, you can use the same ISO 8601 string for the yaml and e.g. properties or toml definition. Fixes #7863
the code smells are all in the regexes i copied from snakeyaml, not going to change those
I'm a bit testy today.
@graemerocher ping
The issue is these are also used for web tier binding not just YAML, have you considered the impact there?
@graemerocher i think it should not be a problem, because string conversion is not affected in the non-error case