Skip to content

Commit b2006f5

Browse files
committed
Fix #4337: support contentConverter for AtomicReference / @JsonSerialize
1 parent 93dd44f commit b2006f5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/ReferenceTypeSerializer.java

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
216216
ser = provider.handlePrimaryContextualization(ser, property);
217217
}
218218
}
219+
// 23-Jan-2024, tatu: May have a content converter:
220+
ser = findContextualConvertingSerializer(provider, property, ser);
221+
219222
// First, resolve wrt property, resolved serializers
220223
ReferenceTypeSerializer<?> refSer;
221224
if ((_property == property)

src/test/java/com/fasterxml/jackson/databind/convert/ConvertingSerializerTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.*;
5+
import java.util.concurrent.atomic.AtomicReference;
56

67
import org.junit.jupiter.api.Test;
78

@@ -101,6 +102,15 @@ public PointListWrapperMap(String key, int x, int y) {
101102
}
102103
}
103104

105+
static class PointReferenceBean {
106+
@JsonSerialize(contentConverter=PointConverter.class)
107+
public AtomicReference<Point> ref;
108+
109+
public PointReferenceBean(int x, int y) {
110+
ref = new AtomicReference<>(new Point(x, y));
111+
}
112+
}
113+
104114
// [databind#357]
105115
static class Value { }
106116

@@ -220,6 +230,12 @@ public void testPropertyAnnotationForMaps() throws Exception {
220230
assertEquals("{\"values\":{\"a\":[1,2]}}", json);
221231
}
222232

233+
@Test
234+
public void testPropertyAnnotationForReferences() throws Exception {
235+
String json = MAPPER.writeValueAsString(new PointReferenceBean(3, 4));
236+
assertEquals("{\"ref\":[3,4]}", json);
237+
}
238+
223239
// [databind#357]
224240
@Test
225241
public void testConverterForList357() throws Exception {

0 commit comments

Comments
 (0)