Skip to content

Allow specifying custom DateTimeFormatter for OffsetDateTime ser/deser (new constructors?) #376

Description

@ZIRAKrezovic

Trying to make OffsetDateTime deserialize from ISO_LOCAL_DATE_TIME pattern by appending default offset of "0". This is easily doable with

    public static final DateTimeFormatter OFFSET_DATE_TIME_PARSER =
            new DateTimeFormatterBuilder()
                    .append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
                    .optionalStart()
                    .parseLenient()
                    .appendOffsetId()
                    .parseStrict()
                    .optionalEnd()
                    .parseDefaulting(ChronoField.OFFSET_SECONDS, 0)
                    .toFormatter();

        var parsed = OffsetDateTime.parse("2025-01-01T22:01:05", OFFSET_DATE_TIME_PARSER);

However, there is no easy way to override this parser, especially since InstantDeserializer.ISO_OFFSET_DATE_TIME is created with many parameters and calls methods that are private to the InstantDeserializer.

When looking at LocalDateTimeDeserializer it as a public constructor that accepts DateTimeFormatter as an arg.

Similar situation happens in OffsetDateTimeSerializer. I wish to only display 3 digits of nano-second instead of 9, but there's no right way to override DateTimeFormatter in OffsetDateTimeSerializer like there's in LocalDateTimeSerializer

Would you kindly support this use-case?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions