-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Using version 2.9.2 or 2.9.8 (and probably many other versions), the following test throws:
JsonMappingException: Cannot find a deserializer for non-concrete Collection type [collection type; class java.util.AbstractSet, contains [simple type, class java.lang.Integer]]
@Test
public void testDeserializeValSet() throws IOException {
new ObjectMapper().readValue("[1,2,3]", ValSet.class);
}
static class ValSet {
@JsonValue
private final AbstractSet<Integer> vals;
@JsonCreator(mode = Mode.DELEGATING)
ValSet(Collection<Integer> vals) {
this.vals = new HashSet<>(vals);
}
public AbstractSet<Integer> getVals() {
return vals;
}
}
This is a spurious error since the @JsonCreator
constructor only requires Collection<Integer>
, not AbstractSet<Integer>
.
Some workarounds:
- Delete
getVals()
. - Make
getVals()
non-public. - Move
@JsonValue
togetVals()
. - Add
@JsonIgnore
togetVals()
. - Add
@JsonAutoDetect(getterVisibility = Visibility.NONE)
toValSet
.
Metadata
Metadata
Assignees
Labels
No labels