diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/ReferenceTypeDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/ReferenceTypeDeserializer.java index 6953da0e9b..251dbc99da 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/ReferenceTypeDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/ReferenceTypeDeserializer.java @@ -66,11 +66,14 @@ public JsonDeserializer createContextual(DeserializationContext ctxt, BeanPro throws JsonMappingException { JsonDeserializer deser = _valueDeserializer; + // 23-Jan-2024, tatu: [databind#4337]: May have a content converter + deser = findConvertingContentDeserializer(ctxt, property, deser); if (deser == null) { deser = ctxt.findContextualValueDeserializer(_fullType.getReferencedType(), property); } else { // otherwise directly assigned, probably not contextual yet: deser = ctxt.handleSecondaryContextualization(deser, property, _fullType.getReferencedType()); } + TypeDeserializer typeDeser = _valueTypeDeserializer; if (typeDeser != null) { typeDeser = typeDeser.forProperty(property); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java index b37102509b..1288d63167 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java @@ -216,7 +216,7 @@ public JsonSerializer createContextual(SerializerProvider provider, ser = provider.handlePrimaryContextualization(ser, property); } } - // 23-Jan-2024, tatu: May have a content converter: + // 23-Jan-2024, tatu: [databind#4337]: May have a content converter ser = findContextualConvertingSerializer(provider, property, ser); // First, resolve wrt property, resolved serializers diff --git a/src/test/java/com/fasterxml/jackson/databind/convert/ConvertingDeserializerTest.java b/src/test/java/com/fasterxml/jackson/databind/convert/ConvertingDeserializerTest.java index bdeb42131c..3388a1bdd4 100644 --- a/src/test/java/com/fasterxml/jackson/databind/convert/ConvertingDeserializerTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/convert/ConvertingDeserializerTest.java @@ -2,11 +2,11 @@ import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.util.StdConverter; @@ -87,6 +87,11 @@ static class PointWrapperMap { public Map values; } + static class PointWrapperReference { + @JsonDeserialize(contentConverter=PointConverter.class) + public AtomicReference ref; + } + static class LowerCaser extends StdConverter { @Override @@ -132,7 +137,7 @@ static class Issue795Bean @Test public void testClassAnnotationSimple() throws Exception { - ConvertingBean bean = objectReader(ConvertingBean.class).readValue("[1,2]"); + ConvertingBean bean = MAPPER.readerFor(ConvertingBean.class).readValue("[1,2]"); assertNotNull(bean); assertEquals(1, bean.x); assertEquals(2, bean.y); @@ -141,7 +146,7 @@ public void testClassAnnotationSimple() throws Exception @Test public void testClassAnnotationForLists() throws Exception { - ConvertingBeanContainer container = objectReader(ConvertingBeanContainer.class) + ConvertingBeanContainer container = MAPPER.readerFor(ConvertingBeanContainer.class) .readValue("{\"values\":[[1,2],[3,4]]}"); assertNotNull(container); assertNotNull(container.values); @@ -152,7 +157,7 @@ public void testClassAnnotationForLists() throws Exception @Test public void testPropertyAnnotationSimple() throws Exception { - PointWrapper wrapper = objectReader(PointWrapper.class).readValue("{\"value\":[3,4]}"); + PointWrapper wrapper = MAPPER.readerFor(PointWrapper.class).readValue("{\"value\":[3,4]}"); assertNotNull(wrapper); assertNotNull(wrapper.value); assertEquals(3, wrapper.value.x); @@ -162,7 +167,7 @@ public void testPropertyAnnotationSimple() throws Exception @Test public void testPropertyAnnotationLowerCasing() throws Exception { - LowerCaseText text = objectReader(LowerCaseText.class).readValue("{\"text\":\"Yay!\"}"); + LowerCaseText text = MAPPER.readerFor(LowerCaseText.class).readValue("{\"text\":\"Yay!\"}"); assertNotNull(text); assertNotNull(text.text); assertEquals("yay!", text.text); @@ -171,7 +176,7 @@ public void testPropertyAnnotationLowerCasing() throws Exception @Test public void testPropertyAnnotationArrayLC() throws Exception { - LowerCaseTextArray texts = objectReader(LowerCaseTextArray.class).readValue("{\"texts\":[\"ABC\"]}"); + LowerCaseTextArray texts = MAPPER.readerFor(LowerCaseTextArray.class).readValue("{\"texts\":[\"ABC\"]}"); assertNotNull(texts); assertNotNull(texts.texts); assertEquals(1, texts.texts.length); @@ -181,7 +186,7 @@ public void testPropertyAnnotationArrayLC() throws Exception @Test public void testPropertyAnnotationForArrays() throws Exception { - PointWrapperArray array = objectReader(PointWrapperArray.class) + PointWrapperArray array = MAPPER.readerFor(PointWrapperArray.class) .readValue("{\"values\":[[4,5],[5,4]]}"); assertNotNull(array); assertNotNull(array.values); @@ -192,7 +197,7 @@ public void testPropertyAnnotationForArrays() throws Exception @Test public void testPropertyAnnotationForLists() throws Exception { - PointWrapperList array = objectReader(PointWrapperList.class) + PointWrapperList array = MAPPER.readerFor(PointWrapperList.class) .readValue("{\"values\":[[7,8],[8,7]]}"); assertNotNull(array); assertNotNull(array.values); @@ -203,7 +208,7 @@ public void testPropertyAnnotationForLists() throws Exception @Test public void testPropertyAnnotationForMaps() throws Exception { - PointWrapperMap map = objectReader(PointWrapperMap.class) + PointWrapperMap map = MAPPER.readerFor(PointWrapperMap.class) .readValue("{\"values\":{\"a\":[1,2]}}"); assertNotNull(map); assertNotNull(map.values); @@ -214,19 +219,28 @@ public void testPropertyAnnotationForMaps() throws Exception assertEquals(2, p.y); } + @Test + public void testPropertyAnnotationForReferences() throws Exception + { + PointWrapperReference w = MAPPER.readerFor(PointWrapperReference.class) + .readValue("{\"ref\": [1,2]}"); + assertNotNull(w); + assertNotNull(w.ref); + Point p = w.ref.get(); + assertNotNull(p); + assertEquals(1, p.x); + assertEquals(2, p.y); + } + // [databind#795] @Test public void testConvertToAbstract() throws Exception { - Issue795Bean bean = objectReader(Issue795Bean.class) + Issue795Bean bean = MAPPER.readerFor(Issue795Bean.class) .readValue("{\"value\":\"1.25\"}"); assertNotNull(bean.value); assertTrue(bean.value instanceof BigDecimal, "Type not BigDecimal but "+bean.value.getClass()); assertEquals(new BigDecimal("1.25"), bean.value); } - - private ObjectReader objectReader(Class type) { - return MAPPER.readerFor(type); - } }