Skip to content

Commit 1fc539c

Browse files
committed
More test refactoring (unification)
1 parent 95d9ce0 commit 1fc539c

File tree

2 files changed

+45
-67
lines changed

2 files changed

+45
-67
lines changed

src/test/java/tools/jackson/databind/ser/AnyGetterOrdering4388Test.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
import com.fasterxml.jackson.annotation.*;
1010

11+
import tools.jackson.databind.MapperFeature;
1112
import tools.jackson.databind.ObjectMapper;
13+
import tools.jackson.databind.SerializationFeature;
14+
import tools.jackson.databind.json.JsonMapper;
1215
import tools.jackson.databind.testutil.DatabindTestUtil;
1316

1417
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -161,6 +164,25 @@ public Map<String, Object> getSecondProperties() {
161164
}
162165
}
163166

167+
// For [databind#5215]: Any-getter should be sorted last, by default
168+
static class DynaBean5215 {
169+
public String l;
170+
public String j;
171+
public String a;
172+
173+
protected Map<String, Object> extensions = new LinkedHashMap<>();
174+
175+
@JsonAnyGetter
176+
public Map<String, Object> getExtensions() {
177+
return extensions;
178+
}
179+
180+
@JsonAnySetter
181+
public void addExtension(String name, Object value) {
182+
extensions.put(name, value);
183+
}
184+
}
185+
164186
/*
165187
/**********************************************************************
166188
/* Test methods
@@ -345,4 +367,27 @@ private void _configureValues(BaseWithProperties base) {
345367
base.products = new HashMap<>();
346368
base.products.put("product1", 4);
347369
}
370+
371+
// For [databind#5215]: Any-getter should be sorted last, by default
372+
@Test
373+
public void dynaBean5215() throws Exception
374+
{
375+
final ObjectMapper mapper = JsonMapper.builder()
376+
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
377+
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
378+
.build();
379+
380+
DynaBean5215 b = new DynaBean5215();
381+
b.a = "1";
382+
b.j = "2";
383+
b.l = "3";
384+
b.addExtension("z", "5");
385+
b.addExtension("b", "4");
386+
assertEquals(a2q("{" +
387+
"'a':'1'," +
388+
"'j':'2'," +
389+
"'l':'3'," +
390+
"'b':'4'," +
391+
"'z':'5'}"), mapper.writeValueAsString(b));
392+
}
348393
}

src/test/java/tools/jackson/databind/ser/AnyGetterOrdering5215Test.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)