Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import tools.jackson.core.Version;
import tools.jackson.databind.DefaultTyping;
import tools.jackson.databind.DeserializationConfig;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.JacksonModule;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.cfg.MapperBuilder;
import tools.jackson.databind.deser.DeserializationContextExt;
import tools.jackson.databind.deser.jackson.BaseNodeDeserializer;
import tools.jackson.databind.deser.jackson.JsonNodeDeserializer;
import tools.jackson.databind.json.JsonMapper;
Expand Down Expand Up @@ -68,6 +68,7 @@
* {@link JacksonObjectWriter}.
*
* @author Christoph Strobl
* @author Tomaz Cerar
* @see JacksonObjectReader
* @see JacksonObjectWriter
* @see ObjectMapper
Expand Down Expand Up @@ -503,10 +504,12 @@ private JsonNode readTree(byte[] source) throws IOException {
}
}

/*
* Hokey pokey! Oh my.
*/
DeserializationContext ctxt = mapper._deserializationContext();
// Bind the parser to the context so its stream-read capabilities are initialized: the node
// deserializer consults them (e.g. StreamReadCapability.DUPLICATE_PROPERTIES when a duplicate
// field name is encountered) and would otherwise throw a NullPointerException. This mirrors the
// way ObjectMapper._readTreeAndClose(...) binds the parser via assignAndReturnParser(...).
DeserializationContextExt ctxt = mapper._deserializationContext();
ctxt.assignParser(parser);

if (t == JsonToken.VALUE_NULL) {
return cfg.getNodeFactory().nullNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.assertj.core.api.InstanceOfAssertFactories.map;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.test.util.ReflectionTestUtils.*;
Expand Down Expand Up @@ -60,6 +61,7 @@
* @author Christoph Strobl
* @author Mark Paluch
* @author John Blum
* @author Tomaz Cerar
*/
class GenericJacksonJsonRedisSerializerUnitTests {

Expand Down Expand Up @@ -178,6 +180,19 @@ void shouldDeserializePrimitiveArrayWithoutTypeHint() {
assertThat(result.getAvailable()).containsExactly(0, 1);
}

@Test // GH-3396
void deserializeShouldHandleDuplicatePropertyWithDefaultTyping() {

// Duplicate property names are valid JSON (RFC 8259) and can appear in cached values written by an
// earlier serializer (e.g. Jackson 2). Resolving the type hint scans the JSON tree, which must not
// fail on a duplicate field (previously a NullPointerException from an unbound DeserializationContext).
byte[] source = "{\"@class\":\"java.util.LinkedHashMap\",\"a\":1,\"a\":2}".getBytes(StandardCharsets.UTF_8);

Object result = serializer.deserialize(source);

assertThat(result).asInstanceOf(map(String.class, Object.class)).containsEntry("a", 2);
}

@Test // GH-2322
void readsToMapForNonDefaultTyping() {

Expand Down