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

InstantSerializer: Passing an invalid string does not yield a SerializationException #169

Closed
florianmutter opened this issue Dec 22, 2021 · 4 comments

Comments

@florianmutter
Copy link

Passing a string that is not a date (e.g. "abc") does not yield a SerializationException. Instead it will yield this exception:

kotlinx.datetime.DateTimeFormatException: java.time.format.DateTimeParseException: Text 'abc' could not be parsed at index 0

In my opinion this excpetion should be wrapped in a SerializationException to be able to have generic error handling if deserialization fails.

@dkhalanskyjb
Copy link
Collaborator

dkhalanskyjb commented Dec 24, 2021

When implementing the serializers, we relied on https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#custom-serializers for stylistic guidance. It doesn't mention SerializationException at all, I believe. We want to adhere to the expectations placed on the custom serializers.

cc @qwwdfsad

@qwwdfsad
Copy link
Contributor

Thanks for pointing it out!

Indeed the documentation has to be improved on kotlin-serialization side: Kotlin/kotlinx.serialization#1875

@dkhalanskyjb
Copy link
Collaborator

According to the issue, us throwing DateTimeFormatException: IllegalArgumentException is stylistically correct, right?

@qwwdfsad
Copy link
Contributor

Right, nothing wrong with it. If you throw it from within your serializer, it may be better to  throw SE, but it's the matter of style

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

3 participants