zio-schema
zio-schema copied to clipboard
Schema deterministic hashcode for DynamicValue
I'm creating a ddd store for Entity and ValueObject.
ValueObject will use it's hashcode as key in the store (and I'll manage collisions storing a list instead of a single value object)
My current approach use something like this:
trait ValueObject[R]:
def schema: Schema[R]
extension (valueObject: R)
def isSameValueObjectAs(other: R): Boolean =
schema.diff(valueObject, other).isIdentical
def valueHashCode: Long =
schema.toDynamic(valueObject).hashCode
This way I can do something like store.getValueObject[T: ValueObject](valueObject: T).filter(found => found.isSameValueObjectAs(valueObject).runHead
However in my tests I observe the hashCode generated using DynamicValue changes, making my code fail.
/bounty $175
💎 $175 bounty • ZIO
Steps to solve:
-
Start working: Comment
/attempt #655
with your implementation plan -
Submit work: Create a pull request including
/claim #655
in the PR body to claim the bounty - 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 bounty • Share on socials
Attempt | Started (GMT+0) | Solution |
---|---|---|
🟢 @BijenderKumar1 | Jun 25, 2024, 3:53:55 AM | #696 |
/attempt #655
I reproduced the issue by creating a DynamicValue object and logging the hashCode
on repeated runs, and it does change. Diving deep into the issue, I observed that there is no implementation for the hashCode
method in the DynamicValue class, and thus the original methods from the Any
class are being used, leading to inconsistency. I am adding an implementation for the hashCode
in the DynamicValue class to resolve the issue. Thanks!
Algora profile | Completed bounties | Tech | Active attempts | Options |
---|---|---|---|---|
@BijenderKumar1 | 1 ZIO bounty | Cancel attempt |
💡 @BijenderKumar1 submitted a pull request that claims the bounty. You can visit your bounty board to reward.
@jdegoes Just a gentle reminder to please review my pull request. Thanks!