8000 Kotlin serialization: Numbers by ulrikandersen · Pull Request #364 · cjbooms/fabrikt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Kotlin serialization: Numbers #364

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

Merged
merged 6 commits into from
Feb 10, 2025

Conversation

ulrikandersen
Copy link
Collaborator
@ulrikandersen ulrikandersen commented Feb 6, 2025

With Jackson we use Java's BigDecimal for numbers without a format keyword, but because Java types are not serializable with Kotlin Serialization we need to use a Kotlin native type instead. I believe the best we can do is Double although it has lower precision than BigDecimal.

Alternatively we could allow the user to provide his own custom serializer for BigDecimal (and other Java types like UUID and URI) as discussed in this issue by annotating the field with @Contexual.

Update:

In order to not loose precision we annotate the field with @Contexual and leave it to the user to provide a custom serializer. This is aligns with the recommended approach in the documentation.

We can add the same possibility for string formats (uuid, uri, base64, binary), but because no precision is lost we could add it as a configuration option. I prefer to do that in a future PR.

With Jackson we can use Java's BigDecimal but since because this is not serializable with Kotlin Serialization we use Double instead.
@ulrikandersen ulrikandersen requested a review from cjbooms February 6, 2025 07:07
@cjbooms
Copy link
Owner
cjbooms commented Feb 6, 2025

I vote for @contextual and letting the users define their own serializer

Not a fan of the pending blog post about a fabrikt being the root cause of a some international banking incident due to loss of precision.

@ulrikandersen
Copy link
Collaborator Author
ulrikandersen commented Feb 7, 2025

I vote for @contextual and letting the users define their own serializer

Not a fan of the pending blog post about a fabrikt being the root cause of a some international banking incident due to loss of precision.

Same here 😬 I'd rather see some positive blog posts 😌

I've updated the PR to add @Contextual and allow the user to provide a serializer.

@cjbooms
Copy link
Owner
cjbooms commented Feb 10, 2025

LGTM - Sorry for the delay

@cjbooms cjbooms merged commit 345b85b into cjbooms:master Feb 10, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants
0