-
Notifications
You must be signed in to change notification settings - Fork 18
Mode.PROPERTIES still does not support single argument constructor. #38
Comments
The docs for
I take that to mean that Mode.PROPERTIES takes away that ambiguity and assumes that a single argument constructor should be used in the same way a multiple argument constructor would be used... |
@hjohn Yes, use of Another thing to try is to use the very latest version -- 2.9.2 -- there is one important fix that affected creator discovery. I do not know if it matters in this case, but it did cause problems with somewhat similar cases. The exception itself does suggest that constructor may not have been auto-discovered, due to lack of |
Also, @hjohn, take a look at FasterXML/jackson-databind#1498. |
I tested it with 2.9.2 -- this made no difference, same exception for the case I presented above. Adding a @JsonCreator to the only constructor made the exception go away... I was trying to avoid that, the project does not have any jackson dependencies there. Still a bug, but I guess it must be tough to fix with the current architecture as it has been present for a long time. |
@hjohn Whether it would be considered a bug or not is bit difficult to say just because exact logic for introspecting constructor is... bit fuzzy. This because at the time databinding was written there was no way to find out names of constructor parameters, so auto-detecting property-based constructors would not have been possible, and as such visibility rules alone are not sufficient for determination. Anyway. It is still possible for you to achieve no-annotations goal via custom |
Thanks, I only re-reported this as Mode.PROPERTIES documentation seems to say that this issue shouldn't arise. Nothing too hard to work-around. Thanks for the clarification. |
@hjohn Ah. Yes, documentation is hard, but it should not give the wrong idea. Btw, the reason why adding |
I have a simple class:
When I serialize this (with private field visibility) I get:
When deserializing (with
new ParameterNamesModule(Mode.PROPERTIES)
) I however get this exception:com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of
A
(although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)What is ambigious here? There is a creator, but it refuses to use it, even though the properties are matches for the parameter names.
If I add a @JsonProperty annotation or a 2nd parameter, the ambiguity disappears. Is it really impossible to tell Jackson to never ever attempt deserializing by passing in a piece of JSON string text? I never want it to use Mode.DELEGATING...
The text was updated successfully, but these errors were encountered: