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 @@ -695,6 +695,13 @@ public ValueSerializer<Object> findPrimaryPropertySerializer(JavaType valueType,
ValueSerializer<Object> ser = _knownSerializers.untypedValueSerializer(valueType);
if (ser == null) {
ser = _createAndCachePropertySerializer(valueType, property);
} else if (property != null) {
// [databind#5405]: property-level @JsonFormat overrides must be applied even with cached serializers
JsonFormat.Value overrides = property.findFormatOverrides(_config);
if (overrides != null && !overrides.equals(JsonFormat.Value.empty())) {
BeanDescription.Supplier beanDescRef = lazyIntrospectBeanDescription(valueType);
ser = _checkShapeShifting(valueType, beanDescRef, property, ser);
}
}
return handlePrimaryContextualization(ser, property);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tools.jackson.databind.tofix;
package tools.jackson.databind;

import java.util.*;

Expand All @@ -8,9 +8,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import tools.jackson.databind.*;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -72,13 +70,23 @@ public Bean5405Override(int value) {
// [databind#5045]: property overrides for @JsonFormat.shape won't work for Maps
// 30-Nov-2025, tatu: Something about caching is the issue: if "b" commented out,
// override appears to work; with "b" not
@JacksonTestFailureExpected
@Test
public void serializeAsPOJOViaProperty() throws Exception
{
String result = MAPPER.writeValueAsString(new Bean5405Container(1,0,3));
assertEquals(a2q(
"{'a':{'extra':13,'empty':false},'c':{'extra':13,'empty':false}}"),
result);
}

// [databind#5405]:
// 01-Dec-2025, JacksonJang: In this case, the @JsonFormat(shape = POJO) override behaves correctly even with b included.
@Test
public void serializeAsPOJOViaFullProperty() throws Exception
{
String result = MAPPER.writeValueAsString(new Bean5405Container(1,2,3));
assertEquals(a2q(
"{'a':{'extra':13,'empty':false},'b':{'value':2},'c':{'extra':13,'empty':false}}"),
"{'a':{'extra':13,'empty':false},'b':{'value':2},'c':{'extra':13,'empty':false}}"),
result);
}

Expand Down