On Thu, Apr 2, 2020 at 3:05 AM maxxyme _ <
max...@gmail.com> wrote:
>
> OK Tatu, thanks for this start of an explanation.
>
> So basically what you're saying is the default `JsonCreator.Mode.DEFAULT` does not make the right "guess", despite what says the Javadoc, or maybe I wrongly understood it?
Your understanding is correct.
> public @interface JsonCreator
> {
> /**
> * Property that is used to indicate how argument(s) is/are bound for creator,
> * in cases there may be multiple alternatives. Currently the one case is that
> * of a single-argument creator method, for which both so-called "delegating" and
> * "property-based" bindings are possible: since
> * delegating mode can not be used for multi-argument creators, the only choice
> * there is "property-based" mode.
> * Check {@link Mode} for more complete explanation of possible choices.
> *<p>
> * Default value of {@link Mode#DEFAULT} means that caller is to use standard
> * heuristics for choosing mode to use.
> *
> * @since 2.5
> */
> public Mode mode() default Mode.DEFAULT;
>
> /**
> * Pseudo-mode that indicates that caller is to use default heuristics for
> * choosing mode to use. This typically favors use of delegating mode for
> * single-argument creators that take structured types.
> */
> DEFAULT,
>
> What does that mean "caller is to use default heuristics"?
That Jackson will try to guess correct mode, based on existence of:
1. Implicit name for one parameter Creator method has, and
2. There are indications of existing property for POJO (as inferred by
getter method)
There may be some other logic based on type of parameter (I'd have to
dig in code to verify), but these are 2 main pieces.
> Am I the caller (or caller code's coder...)? So am I supposed to effectively choose a specific mode and not use the DEFAULT one?
Caller here would mean Jackson databind's code that invokes creator method.
You as developer should specify mode if heuristics does not work, or,
if you just want to ensure right mode is used. I would recommend
latter.
That is right.
You are trying to bind a JSON Object into String value (delegation
means "bind JSON value, whatever it may be, into value of type I
have).
If content you get is JSON Object, you would either:
1. Specify "Properties" style: in this case there is no actual
property with matching name so `null` would be passed
2. Keep Delegating style, but bind to something that is compatible
with JSON Object: for example, Map<String, Object>
> com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `Inner` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
> at [Source: (String)"{"inner":{}}"; line: 1, column: 2]
>
> com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `Inner` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
> at [Source: (String)"{"inner":{"prop":"42"}}"; line: 1, column: 2]
>
> I still don't get what I'm doing wrong...
It seems to me that you are explaining what happens, instead of what
you are trying to achieve.
It would be easier to help if I knew what you try to do.
-+ Tatu +-
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
jackson-user...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/4e07dcf0-74f3-4bcb-b669-5a2f16256d2c%40googlegroups.com.