|
8 | 8 |
|
9 | 9 | import com.fasterxml.jackson.annotation.*; |
10 | 10 |
|
| 11 | +import tools.jackson.databind.MapperFeature; |
11 | 12 | import tools.jackson.databind.ObjectMapper; |
| 13 | +import tools.jackson.databind.SerializationFeature; |
| 14 | +import tools.jackson.databind.json.JsonMapper; |
12 | 15 | import tools.jackson.databind.testutil.DatabindTestUtil; |
13 | 16 |
|
14 | 17 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -161,6 +164,25 @@ public Map<String, Object> getSecondProperties() { |
161 | 164 | } |
162 | 165 | } |
163 | 166 |
|
| 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 | + |
164 | 186 | /* |
165 | 187 | /********************************************************************** |
166 | 188 | /* Test methods |
@@ -345,4 +367,27 @@ private void _configureValues(BaseWithProperties base) { |
345 | 367 | base.products = new HashMap<>(); |
346 | 368 | base.products.put("product1", 4); |
347 | 369 | } |
| 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 | + } |
348 | 393 | } |
0 commit comments