Skip to content

Commit

Permalink
Fix wrapped array hanlding wrt null by StdDeserializer (#4844)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorrian authored Dec 12, 2024
1 parent d8d0714 commit 8cfa8ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ protected T _deserializeWrappedValue(JsonParser p, DeserializationContext ctxt)
T result = (T) handleNestedArrayForSingle(p, ctxt);
return result;
}
// 11-Dec-2024: [databind#4844] Caller needs to handle nulls before delegating
if (p.hasToken(JsonToken.VALUE_NULL)) {
return getNullValue(ctxt);
}
return (T) deserialize(p, ctxt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
Expand All @@ -19,6 +21,10 @@ public class UnwrapSingleArrayMiscTest extends DatabindTestUtil
.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
.build();

static class StringWrapper {
public String value;
}

/*
/**********************************************************
/* Tests methods, POJOs
Expand Down Expand Up @@ -78,4 +84,16 @@ public void testEnumMapUnwrapping() throws Exception
verifyException(e, "more than one value");
}
}

// [databind#4844]: should work for wrapped null values too
@Test
public void testDeserializeArrayWithNullElement() throws Exception
{
StringWrapper v = UNWRAPPING_MAPPER
.readerFor(StringWrapper.class)
.readValue("{\"value\": [null]}");

assertNotNull(v);
assertNull(v.value);
}
}

0 comments on commit 8cfa8ba

Please sign in to comment.