-
-
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
IllegalArgumentException: Conflicting setter definitions for property with more than 2 setters #3125
Comments
Yes, you have multiple As to why one seems to be used over another one, that seems suboptimal. But you are using an old version of jackson-databind so it might be worth checking with 2.11.4 first (in fact, before submitting an issue one always should at least try the latest patch of given minor version!); and if possible, 2.12.3. |
Thanks for your quick reply. Of course, I can use I'm sorry, I the version I mentioned is not the latest one. I said I have read this part of the source code (on the latest master branch), but no changes are found. In fact, I tried both 2.11.4 and 2.12.3 just now, problems remain. My confusion is, if jackson does not consider to support multiple setters, some exception should always be thrown. then, what does the following code doing? jackson-databind/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java Line 456 in a0ef91c
If multiple setters are supported, the above code works fine, only if at least one setter with |
I agree: if there are 2 conflicting setters, problem should be reported -- no Heisenbugs allowed. I was just hoping that this was one of the cases that was patched against; I forget which issue changes were for (perhaps #426?) but there were changes to tighten detection fairly recently. I can't spot the problem immediately but it sounds like there is one. So this sounds like a bug, will leave open; hoping to have time to look into this. Fix should likely go in 2.13 since I have learned that quite often bugs like this are features someone somewhere relies on... (less surprises in patches, fixes need to go in minor releases) |
I don't think they are the same issue, I do not want to ignore this property. I am not sure if I understand the real intention of the
However, this is just an immature idea of mine. |
The code is there to do process as follows:
So In this case what I don't understand is why and how ordering of setters would prevent conflict indication: to me this seems like a clear case of conflict. |
Thanks for your explanation. I still don't understand, why two setters (with String or assignable type) works if at most one mutator is accepted. Is it considered for super class? Back to the Let's try the following case, In the brackets is the type of
These cases should be able to explain the problem. All goes well till these lines:
The
|
On setter: key questions is this: is there at most one obvious choice to use or not? But as to 3 choices, 2 not acceptable -- not acceptable based on what? Why wouldn't they be?
Keep in mind that resolution has no knowledge of kind of input there might be: so it would not be making any choices like "can not use But looking at As to why |
Ok. So reading through Actual precedence is, as you stated:
This is at point where other rules would have been applied (annotation trumps non-annotated; sub-class preferred over super-class). Changes were made in 2.7.0, under #1044, so logic is at this point expected default for Jackson 2.x. In that sense, it seems that But the remaining big problem is the fact that pair-wise detection does not work without doing full set of calls, because a pair of instances with "other" type might be selected first. I will have to think about this a bit. |
I think I know at high level how this should work -- as suggested, kind of, existence of 2 equal-precedence setters does NOT in itself yet signal a problem; rather, in such case, processing needs to continue to possibly find something at higher level (in this case |
Yes! I think I have provided enough information for the problem. These cases are generally rare. In fact, I originally thought that Jackson could automatically decide which setter to use according to the type of the input data to be deserialized. This is due to the compatibility problem of the two versions. The serialized output of the old version is String (name of enum), but the new version output is Integer (ordinal of enum) (This may not be a good design, but sometimes it has to be). From the rules of java method overloading, there should be no conflict. If Jackson can better support this feature, it will be even more perfect. Of course, Jackson can make its own rules and do strict inspections. This case is a performance that is inconsistent with the expectations of the rules. By the way, to this problem, currently, my final solution is to add @JsonIgnore annotations to all three setters, and then add a new setter with a parameter type of Object and add @JsonProperty annotations to it. I do the corresponding processing inside according to the data type myself. |
Yes I finally understand the problem and once I have time will solve it; the problem is just doing it cleanly. :) As to working around the issue: no need to |
Hi,
I am using jackson-databind:2.11.1, for some special reason, I must provide multiple compatible setters, I got failed with the following case:
Try a few more times, sometimes it works fine, and sometimes it throws IllegalArgumentException (Conflicting setter definitions for property).
I have read this part of the source code, the course is probably in the POJOPropertyBuilder.getSetter() method. It seems prefer to the setter with String parameter, and can choose the right one (the one with String parameter) when there are 2 or less setters. In my case, there are 3, If the setter with String parameter is not first two, the exception will be thrown. but it seems that, the order of setters are indeterminate.
I've found a similar issue here #2741, but it was a different case.
The text was updated successfully, but these errors were encountered: