micronaut-core icon indicating copy to clipboard operation
micronaut-core copied to clipboard

More java.time support for yaml and converters

Open yawkat opened this issue 1 year ago • 3 comments

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

yawkat avatar Aug 12 '22 11:08 yawkat

the code smells are all in the regexes i copied from snakeyaml, not going to change those

yawkat avatar Aug 12 '22 12:08 yawkat

I'm a bit testy today.

yawkat avatar Aug 12 '22 13:08 yawkat

@graemerocher ping

sdelamo avatar Sep 07 '22 17:09 sdelamo

The issue is these are also used for web tier binding not just YAML, have you considered the impact there?

graemerocher avatar Sep 13 '22 13:09 graemerocher

@graemerocher i think it should not be a problem, because string conversion is not affected in the non-error case

yawkat avatar Sep 13 '22 13:09 yawkat