Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 16, 2024
2 parents a2f7f66 + d2a29b7 commit 00a2399
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 4 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Project: jackson-databind

2.18.1 (WIP-2024)

#4741: When `Include.NON_DEFAULT` setting is used on POJO, empty values
are not included in json if default is `null`
(reported by @ragnhov)
(fix by Joo-Hyuk K)
#4749: Fixed a problem with `StdDelegatingSerializer#serializeWithType` looking up the serializer
with the wrong argument
(fix by wrongwrong)
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/tools/jackson/databind/ser/PropertyBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ protected BeanPropertyWriter buildWriter(SerializerProvider ctxt,
}
if (valueToSuppress == null) {
suppressNulls = true;
// [databind#4464] NON_DEFAULT does not work with NON_EMPTY for custom serializer
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
// [databind#4471] Different behavior when Include.NON_DEFAULT
// setting is used on POJO vs global setting, as per documentation.
if (!_useRealPropertyDefaults) {
// [databind#4464] NON_DEFAULT does not work with NON_EMPTY for custom serializer
valueToSuppress = BeanPropertyWriter.MARKER_FOR_EMPTY;
}
} else {
if (valueToSuppress.getClass().isArray()) {
valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tools.jackson.databind.ser.filter;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonInclude;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;

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

public class JsonInclude4741Test
extends DatabindTestUtil
{
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public static class MyString {
public String value = null;
}

private final ObjectMapper MAPPER = newJsonMapper();

@Test
void testSerialization() throws Exception
{
MyString input = new MyString();
input.value = "";

String json = MAPPER.writeValueAsString(input);
assertEquals(a2q("{'value':''}"), json);

MyString output = MAPPER.readValue(json, MyString.class);

assertEquals(input.value, output.value);
}
}

0 comments on commit 00a2399

Please sign in to comment.