-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
default mapper cannot handle basic immutable class #3898
default mapper cannot handle basic immutable class #3898
Conversation
There are 2 related problems as to why this can't quite be made to work at this point. The main problem is that the names of Constructor parameters are only available with Parameter names module (or by Kotlin/Scala module providing implicit names similarly). Second challenge is figuring out choice between Properties- and Delegating- Creator; this because 1-argument case is fundamentally ambiguous. Anyway: adding implicit parameter name access, I think this test might actually pass already? |
I tried various changes to the ImmutableId class. The prop names were not a problem. None of these helped:
The main reason for the ParamNamesModule is Java 6 and 7 - Java 8+ has better support for finding parameter names. In the end, the only thing that helped was adding an extra no-param constructor. It is not ideal to have it such that users need to modify their classes to get deserialization to work. |
Use of But generally we could solve this if Property Discovery was rewritten -- my long-term nr 1 target. There's #3719 related to that; explaining the issue. Downside is that I do not thing incremental smaller changes allow doing what is ideal; we have probably ran out of incremental fixes and new ones are likely counter-productive (adding hacks to handle individual problem cases, leading to more complex and error-prone combinations). As to timeline, it's been "next minor version" since maybe 2.12. But lately vuln/cve focus has taken lots of time. Maybe with 2.16 things are different. :) EDIT: (10-Jun-2024) Above-mentioned property discovery rewrite was done via #4515 and is now in 2.18 branch. |
@pjfanning After rebasing to 2.18, merging changes to latest, updating wrt JUnit 5 test changes, all 5 tests now actually pass (probably due to #4515)! (when running locally, failing tests would be skipped on CI) But I am not sure what to do with the tests however, as I think they probably overlap with other tests under WDYT? Some of these could be merged with existing |
@cowtowncoder I moved the test to the 'ser' package. I think it is useful to add this test class as a regression scenario. |
Ok. I'll probably move it to under "creators" (since that's where |
The test in this PR fails with:
As someone who codes mainly in Scala, this is how I prefer to create Java Beans - with immutable values - thus, no setters.
I know we have Java Records but this style is useful for older Java runtimes.
Is there any chance that this could be made to work with a default mapper with no annotations or customisation of the mapper?