Skip to content

Commit deed3b0

Browse files
Stanislav Shcherbakovcowtowncoder
Stanislav Shcherbakov
authored andcommitted
Fix wrapped array hanlding wrt null by StdDeserializer (#4844)
1 parent 7d187c9 commit deed3b0

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
@@ -361,6 +361,10 @@ protected T _deserializeWrappedValue(JsonParser p, DeserializationContext ctxt)
361361
T result = (T) handleNestedArrayForSingle(p, ctxt);
362362
return result;
363363
}
364+
// 11-Dec-2024: [databind#4844] Caller needs to handle nulls before delegating
365+
if (p.hasToken(JsonToken.VALUE_NULL)) {
366+
return getNullValue(ctxt);
367+
}
364368
return (T) deserialize(p, ctxt);
365369
}
366370

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)