Skip to content

Formatting and Parsing of Large ISO-8601 Dates is inconsistent #5429

@DavTurns

Description

@DavTurns

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

As already addressed in #2167 Jackson adds a leading “+” for ISO-8601 dates (expanded representation) when the year value is greater than 9999, and “–” for BCE dates, during serialization.
However, deserialization of these ISO-8601 dates does not work in reverse.

Version Information

2.19.2

Reproduction

import com.fasterxml.jackson.databind.util.StdDateFormat;

import java.text.ParseException;
import java.util.Date;

class StdDateFormatTest {
    public static void main(String[] args) throws ParseException {
        StdDateFormat formatter = new StdDateFormat();
        Date dateFuture = new Date(Long.MAX_VALUE);
        Date datePast = new Date(Long.MIN_VALUE);
        
        //this part works fine
        String dateFutureAsString = formatter.format(dateFuture);
        String datePastAsString = formatter.format(datePast);

        // The test fails because parsing back throws ParseException
        Date parsedBackDateFuture = formatter.parse(dateFutureAsString);
        Date parsedBackDatePast = formatter.parse(datePastAsString);

        assert parsedBackDateFuture.getTime() == dateFuture.getTime();
        assert parsedBackDatePast.getTime() == datePast.getTime();
    }
}

Expected behavior

All formatted dates are being parsed back correctly.

Additional context

Location:

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions