Skip to content

Commit

Permalink
Fix #4337: support @JsonSerialize(contentConverter) with `AtomicRef…
Browse files Browse the repository at this point in the history
…erence` (#4338)
  • Loading branch information
cowtowncoder authored Jan 24, 2024
1 parent 93dd44f commit 215557b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Project: jackson-databind
deserialization with `READ_UNKNOWN_ENUM_VALUES_AS_NULL` and `FAIL_ON_INVALID_SUBTYPE` wrong
(reported by @ivan-zaitsev)
(fix contributed by Joo-Hyuk K)
#4337: `AtomicReference` serializer does not support `@JsonSerialize(contentConverter=...)`
2.16.2 (not yet released)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
ser = provider.handlePrimaryContextualization(ser, property);
}
}
// 23-Jan-2024, tatu: May have a content converter:
ser = findContextualConvertingSerializer(provider, property, ser);

// First, resolve wrt property, resolved serializers
ReferenceTypeSerializer<?> refSer;
if ((_property == property)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -101,6 +102,15 @@ public PointListWrapperMap(String key, int x, int y) {
}
}

static class PointReferenceBean {
@JsonSerialize(contentConverter=PointConverter.class)
public AtomicReference<Point> ref;

public PointReferenceBean(int x, int y) {
ref = new AtomicReference<>(new Point(x, y));
}
}

// [databind#357]
static class Value { }

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

@Test
public void testPropertyAnnotationForReferences() throws Exception {
String json = MAPPER.writeValueAsString(new PointReferenceBean(3, 4));
assertEquals("{\"ref\":[3,4]}", json);
}

// [databind#357]
@Test
public void testConverterForList357() throws Exception {
Expand Down

0 comments on commit 215557b

Please sign in to comment.