Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DeserializationContext.handleWeirdXxxValue() for datetime deserializers #65

Closed
remal opened this issue Apr 3, 2018 · 1 comment
Closed
Milestone

Comments

@remal
Copy link
Contributor

remal commented Apr 3, 2018

Lets look on LocalDateTimeDeserializer (for example):

public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        // ...
        try {
            // ...
            return LocalDateTime.parse(string, _formatter);
        } catch (DateTimeException e) {
            _rethrowDateTimeException(parser, context, e, string);
        }
    }
    // ...
}

Please change it to:

public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        // ...
        try {
            // ...
            return LocalDateTime.parse(string, _formatter);
        } catch (DateTimeException e) {
            try {
                return context.handleWeirdStringValue(LocalDateTime.class, string, e.getMessage());
            } catch (Throwable t) {
                t.initCause(e);
            }
        }
    }
    // ...
}

Why do I need this? I want to create a module that defines some DeserializationProblemHandlers that allow to deserialize datetime types using several formats. Now I need to create mix-ins to override datetime deserializers.

Please apply this change to all deserializers and key deserializers.

@cowtowncoder
Copy link
Member

Makes sense. I'll add notes to PR itself.

@cowtowncoder cowtowncoder changed the title Please use DeserializationContext.handleWeird*Value for datetime deserializers Use DeserializationContext.handleWeirdXxxValue() for datetime deserializers Apr 5, 2018
@cowtowncoder cowtowncoder modified the milestones: 2.9.0.pr2, 2.9.6 Apr 5, 2018
cowtowncoder added a commit that referenced this issue Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants