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

Class java.math.BigDecimal cannot be cast to class scala.math.BigDecimal in schema-bson #663

Closed
bsaletti opened this issue Feb 23, 2024 · 4 comments · Fixed by #687
Closed

Comments

@bsaletti
Copy link

Hello,

I'm trying to make a rest api with zio ecosystem and mongoDB.

When I tring to encode scala.math.BigDecimal in mongoDB, I have this error =>

class java.math.BigDecimal cannot be cast to class scala.math.BigDecimal (java.math.BigDecimal is in module java.base of loader 'bootstrap'; scala.math.BigDecimal is in unnamed module of loader 'app')

I changed
case StandardType.BigDecimalType => BsonCodec.bigDecimal.asInstanceOf[BsonCodec[A]]
to
case StandardType.BigDecimalType => BsonCodec.javaBigDecimal.asInstanceOf[BsonCodec[A]]

case StandardType.BigDecimalType => BsonCodec.bigDecimal.asInstanceOf[BsonCodec[A]]

And this solved the problem

@jdegoes
Copy link
Member

jdegoes commented Jun 8, 2024

/bounty $50

Copy link

algora-pbc bot commented Jun 8, 2024

💎 $50 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #663 with your implementation plan
  2. Submit work: Create a pull request including /claim #663 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-schema!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @abhishek818 #687

abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 8, 2024
Copy link

algora-pbc bot commented Jun 8, 2024

💡 @abhishek818 submitted a pull request that claims the bounty. You can visit your bounty board to reward.

abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 8, 2024
refer the codec defintion in zio-bson repo :
zio/zio-bson/src/main/scala/zio/bson/BsonCodec.scala#L80
abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 12, 2024
abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 12, 2024
refer the codec defintion in zio-bson repo :
zio/zio-bson/src/main/scala/zio/bson/BsonCodec.scala#L80
abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 12, 2024
abhishek818 added a commit to abhishek818/zio-schema that referenced this issue Jun 12, 2024
jdegoes pushed a commit that referenced this issue Jun 12, 2024
* update the codec for big decimal (#663)

refer the codec defintion in zio-bson repo :
zio/zio-bson/src/main/scala/zio/bson/BsonCodec.scala#L80

* add test case for BigDecimal's codec (#663)
Copy link

algora-pbc bot commented Jun 12, 2024

🎉🎈 @abhishek818 has been awarded $50! 🎈🎊

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

Successfully merging a pull request may close this issue.

2 participants