Skip to content

Commit

Permalink
Add test with link/unlink property
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim committed Feb 27, 2024
1 parent 8305a0b commit 85ae52e
Showing 1 changed file with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

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


/**
* Test to verify that the order of properties is preserved when using @JsonPropertyOrder
* with @JsonUnwrapped and @JsonAnyGetter
*/
public class JsonPropertyOrder4388Test extends DatabindTestUtil
{
public class JsonPropertyOrder4388Test extends DatabindTestUtil {
// Base class with properties
static class BaseWithProperties {
public String entityName;
Expand Down Expand Up @@ -94,6 +92,28 @@ static class AlphabeticOrderOnClassBean {
public Map<String, Object> map = new LinkedHashMap<>();
}

static class LinkUnlinkConflictPojo {
private Map<String, Object> properties = new HashMap<>();

@JsonAnyGetter
public Map<String, Object> getProperties() {
properties.put("key", "value");
return properties;
}

@JsonIgnore
public String getProperties(String key) {
// This method is unrelated to the any-getter and should not affect serialization
return "unrelated";
}

@JsonIgnore
public String getKey() {
// This method is unrelated to the any-getter and should not affect serialization
return "unrelated";
}
}

private final ObjectMapper MAPPER = newJsonMapper();

// For [databind#4388]
Expand Down Expand Up @@ -165,17 +185,6 @@ public void testSerializationOrderUnwrappedVersion2() throws Exception {
json);
}

private void _configureValues(BaseWithProperties base) {
base.entityId = 1;
base.entityName = "Bob";
base.totalTests = 2;
base.childEntities = new Location();
base.childEntities.child1 = 3;
base.childEntities.child2 = 3;
base.products = new HashMap<>();
base.products.put("product1", 4);
}

@Test
public void testIgnoreProperties() throws Exception {
// Respsect @JsonIgnoreProperties 'b' from Pojo, but not from map
Expand Down Expand Up @@ -224,4 +233,23 @@ public void testSortingOnClassNotPropagateToAnyGetter() throws Exception {
"'za':1," +
"'zb':2}"), MAPPER.writeValueAsString(bean));
}

@Test
public void testLinkUnlinkWithJsonIgnore() throws Exception {
LinkUnlinkConflictPojo pojo = new LinkUnlinkConflictPojo();
String json = MAPPER.writeValueAsString(pojo);

assertEquals(a2q("{'key':'value'}"), json);
}

private void _configureValues(BaseWithProperties base) {
base.entityId = 1;
base.entityName = "Bob";
base.totalTests = 2;
base.childEntities = new Location();
base.childEntities.child1 = 3;
base.childEntities.child2 = 3;
base.products = new HashMap<>();
base.products.put("product1", 4);
}
}

0 comments on commit 85ae52e

Please sign in to comment.