Skip to content

Commit

Permalink
fix and test
Browse files Browse the repository at this point in the history
Fix and test

Delete GoodTest.java
  • Loading branch information
JooHyukKim committed Oct 10, 2024
1 parent 03de9a1 commit 3a97f07
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,14 @@ protected BeanPropertyWriter buildWriter(SerializerProvider prov,
}
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] Since 2.18.1 Different behavior when Include.NON_DEFAULT setting is used on
// POJO vs global setting, as per documentation.
boolean isGloballyConfigured = _config.getDefaultInclusion(actualType.getRawClass(), rawPropertyType)
.getValueInclusion() == JsonInclude.Include.NON_DEFAULT;
if (isGloballyConfigured) {
// [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,44 @@
package com.fasterxml.jackson.databind.ser.filter;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import org.junit.jupiter.api.Test;

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

public class JsonInclude4741Test
extends DatabindTestUtil
{

private ObjectMapper MAPPER = newJsonMapper();

@Test
void testSerialization() throws JsonProcessingException
{
MyString input = new MyString();
input.setValue("");

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

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

@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public static class MyString {
private String value = null;

// Getter
public String getValue() {
return value;
}

// Setter
public void setValue(String value) {
this.value = value;
}
}
}

0 comments on commit 3a97f07

Please sign in to comment.