On Fri, Jul 26, 2019 at 1:46 PM Marcin Kwapisz
<[email protected]> wrote:
>
> A few days ago I stuck with the problem in the topic. I found a solution and
> described it on Stackoverflow.
>
> Here I would like to ask why I cannot use @JsonCreator annotated methods or
> constructors and why a parameterless constructor is required on one side.
> This is the first time I use Jackson, just because I had to
> serialize/deserialize Java objects with circular references
It is difficult to answer the question without digging deeper, but
here are some notes:
1. Use of constructors / factory methods requires buffering of
properties and may result in cyclic cases where it is literally
impossible to construct where there is a cycle between values needed
for creator methods (cosntructor / factory). For example:
public class A {
@JsonCreator A(B child) { ... }
}
public class B {
@JsonCreator B(A parent) { .... }
}
is impossible to resolve. So sometimes it may be necessary to
leave out one particular dependency from Creator, and pass it via
setter (or directly assignt o field)
2. Use of `@JsonCreator` is optional if (and only if) all Creator
parameters have explicit marker (and unless parameter names available,
name) -- that is, `@JsonProperty`.
3. Factory methods are not auto-detected, and must be `@JsonCreator`
annotated; also must return type of declaring class (or subtype).
4. If no Creator method is discovered, then (but only then) a
no-arguments Constructor is required
Not sure if this helps answering the question. I can not see any
obvious problem in your original example, so it might be worth filing
an issue (against `jackson-databind`) for.
-+ 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/CAL4a10h%3DoU4TaAB%2BpYn7t5SGSxFvE8oJOujCtbcbt4ytAx00Xg%40mail.gmail.com.