Skip to content

Commit 8cfa8ba

Browse files
author
Stanislav Shcherbakov
authored
Fix wrapped array hanlding wrt null by StdDeserializer (#4844)
1 parent d8d0714 commit 8cfa8ba

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java

+4
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ protected T _deserializeWrappedValue(JsonParser p, DeserializationContext ctxt)
360360
T result = (T) handleNestedArrayForSingle(p, ctxt);
361361
return result;
362362
}
363+
// 11-Dec-2024: [databind#4844] Caller needs to handle nulls before delegating
364+
if (p.hasToken(JsonToken.VALUE_NULL)) {
365+
return getNullValue(ctxt);
366+
}
363367
return (T) deserialize(p, ctxt);
364368
}
365369

src/test/java/com/fasterxml/jackson/databind/struct/UnwrapSingleArrayMiscTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import org.junit.jupiter.api.Test;
88

9+
import com.fasterxml.jackson.core.JsonFactory;
10+
import com.fasterxml.jackson.core.JsonParser;
911
import com.fasterxml.jackson.core.type.TypeReference;
1012
import com.fasterxml.jackson.databind.*;
1113
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
@@ -19,6 +21,10 @@ public class UnwrapSingleArrayMiscTest extends DatabindTestUtil
1921
.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
2022
.build();
2123

24+
static class StringWrapper {
25+
public String value;
26+
}
27+
2228
/*
2329
/**********************************************************
2430
/* Tests methods, POJOs
@@ -78,4 +84,16 @@ public void testEnumMapUnwrapping() throws Exception
7884
verifyException(e, "more than one value");
7985
}
8086
}
87+
88+
// [databind#4844]: should work for wrapped null values too
89+
@Test
90+
public void testDeserializeArrayWithNullElement() throws Exception
91+
{
92+
StringWrapper v = UNWRAPPING_MAPPER
93+
.readerFor(StringWrapper.class)
94+
.readValue("{\"value\": [null]}");
95+
96+
assertNotNull(v);
97+
assertNull(v.value);
98+
}
8199
}

0 commit comments

Comments
 (0)