Closed
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
There seems to be a problem with the following code
Jackson
may deserialize empty characters in an array on JSON
to null
.
In this case, JsonToken
will be VALUE_STRING
instead of VALUE_NULL
.
On the other hand, in the code presented, Nulls.SKIP
and Nulls.FAIL
are only applied if it is VALUE_NULL
.
(To be precise, Nulls.SKIP
works. However, it seems that the decision regarding _skipNullValues
is being made in two places, which I feel should be improved).
Version Information
2.19.0
Reproduction
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.exc.InvalidNullException;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestGitHubXXX {
static class Dst {
private List<Integer> list;
public List<Integer> getList() {
return list;
}
public void setList(List<Integer> list) {
this.list = list;
}
}
@Test
public void nullsFailTest() {
ObjectMapper mapper = new ObjectMapper();
mapper.configOverride(List.class).setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.FAIL));
assertThrows(
InvalidNullException.class,
() -> mapper.readValue("{\"list\":[\"\"]}", new TypeReference<Dst>(){})
);
}
@Test
public void nullsSkipTest() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.configOverride(List.class).setSetterInfo(JsonSetter.Value.forContentNulls(Nulls.SKIP));
Dst dst = mapper.readValue("{\"list\":[\"\"]}", new TypeReference<>() {});
assertTrue(dst.getList().isEmpty());
}
}
Expected behavior
The JsonSetter.contentNulls
must function properly.
Additional context
This was discovered by a bug report to kotlin-module
.
FasterXML/jackson-module-kotlin#976