Closed ymwangzq closed 2 years ago
Sounds like a bug, thank you for reporting this.
Ah. This is not a bug in deserializer but POJO definition.
The issue is constructor annotation @JsonCreator
: when constructor only takes 1 parameter, there are 2 interpretations of how binding should work; and in this case, without more information, code guesses incorrectly that value should be so-called "delegating" (so the parameter value should be the "whole" incoming value and not one of the properties from incoming JSON Object).
Long story short, you need to do it like so:
static class Pojo1 {
@JsonProperty
private final ArrayListMultimap<Long, Integer> multimap;
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public Pojo1(@JsonProperty("multimap") ArrayListMultimap<Long, Integer> multimap) {
this.multimap = multimap;
}
(note: if you are using jackson-module-parameter-names
, use of @JsonProperty
for creator parameter is optional)
and with that code works as expected.
Exception that you get is not very descriptive so it is bit difficult to figure out unless you happen to know about the complexity of this particular case. I'll see if I can figure out an improvement to error handling here.
This is my code:
This test throws an exception:
This is my dependencies: