-
Notifications
You must be signed in to change notification settings - Fork 13
Equality override #10
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
base: master
Are you sure you want to change the base?
Conversation
|
This is tricky and tedious in Java for a number of reasons. Equality basically works like this in Java:
Contrast this with how inequality works in Java:
When writing POJOs or DTOs by hand, people are often tempted to implement Do you have a specific use case that motivated this PR? |
|
I would like to use your library to cut out a large amount of boilerplate code on my domain model objects. Those objects have domain specific equality rules. I'm looking for a hook into the DynamicObjectInstance I totally get what you're saying, This your library and if you want to make it opinionated that's great. I would appreciate hooks into the I'm open to other suggestions. |
|
There are many libraries in modern Java development that do boilerplate elimination. My personal favorite is Immutables, and I've also used Lombok extensively and AutoValue a bit. These libraries are implemented in such a way that it is much more straightforward to override |
|
Lombok is nice but not really what I was looking for. Elimination of boilerplate is only half the reason I was looking at dynamic-object. I've been building my domain model as map backed objects by hand for a while now. Maps are easier to serialize to and from json and/or bson but it's a pain to have to code the getters and builders. I liked how you're generating the map backed implementation at runtime and the serialization is event easier to work with than using something like Gson. The schema validation and metadata features are nice as well. It's fine to tell me I'm out of luck with these equality rules. I'll figure something else out. |
|
Customizing |
functions instead of requiring the implementation of Equality interface
|
I'm not sure if this was what you had in mind but I removed the |
I'm guessing this goes against some clojure principal but this change would allow object to override equals and hashcode by implementing the com.github.rschmitt.dynamicobject.Equality interface and adding default implementations of isEqualTo and getHashCode(). The com.github.rschmitt.dynamicobject.EqualityTest gives and example of when this sort of override would be useful.