jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

`@JacksonInject` causes deserialization failure (unresolved forward reference)

Open cowwoc opened this issue 9 years ago • 3 comments

Jackson 2.4.4 is able to successfully deserialize forward references, but it fails to do so if the constructor contains a @JacksonInject parameter.

cowwoc avatar Nov 28 '14 19:11 cowwoc

Testcase: https://gist.github.com/cowwoc/743d2839bc7297a47516

cowwoc avatar Nov 28 '14 19:11 cowwoc

Actually I think this is different, and bit trickier. Problem is that there is an actual cycle from deserializer perspective, since parent2 may not be constructed before all JSON for it (and its descendants) are consumed; but its child child2 needs parent reference passed via constructor. So the solution here would be to remove @JsonCreator on child2 with non-creator alternative.

Except that in theory, since parent2 only needs injectable value, perhaps implementing #1268 would allow this to be handled even without removing of @JsonCreator.

cowtowncoder avatar Jun 15 '16 06:06 cowtowncoder

So, the json output here is something like:

{"@id":1,"child":{"@id":2,"parent":1}}

and the reason this can not be resolved at this point is only partially due to @JacksonInject. The underlying problem is that neither Parent2 nor Child2 may be constructed before all data is available, as both have @JsonCreator annotated constructor. Now, in theory Jackson could notice that the only parameter for Parent2 is injectable and create it immediately -- however, before #1381 is implemented, there is no way to indicate that something is purely injectable, that is, something that only comes via injection and not data. With #1268 it should be possible to define this, and with that, this problem would be solvable theoretically.

cowtowncoder avatar Jul 19 '16 01:07 cowtowncoder