|
7 | 7 | import org.junit.jupiter.api.Test; |
8 | 8 |
|
9 | 9 | import com.fasterxml.jackson.annotation.*; |
| 10 | + |
10 | 11 | import tools.jackson.databind.ObjectMapper; |
11 | 12 | import tools.jackson.databind.testutil.DatabindTestUtil; |
12 | 13 |
|
|
16 | 17 | * Test to verify that the order of properties is preserved when using @JsonPropertyOrder |
17 | 18 | * with @JsonUnwrapped and @JsonAnyGetter |
18 | 19 | */ |
19 | | -public class AnyGetterOrdering4388Test extends DatabindTestUtil { |
| 20 | +public class AnyGetterOrdering4388Test extends DatabindTestUtil |
| 21 | +{ |
| 22 | + // For [databind#518] |
| 23 | + |
| 24 | + @JsonPropertyOrder(alphabetic = true) |
| 25 | + static class Bean518 |
| 26 | + { |
| 27 | + public int b; |
| 28 | + |
| 29 | + protected Map<String,Object> extra = new HashMap<>(); |
| 30 | + |
| 31 | + public int a; |
| 32 | + |
| 33 | + public Bean518(int a, int b, Map<String,Object> x) { |
| 34 | + this.a = a; |
| 35 | + this.b = b; |
| 36 | + extra = x; |
| 37 | + } |
| 38 | + |
| 39 | + @JsonAnyGetter |
| 40 | + public Map<String,Object> getExtra() { return extra; } |
| 41 | + } |
| 42 | + |
| 43 | + // For [databind#4388] |
| 44 | + |
20 | 45 | // Base class with properties |
21 | 46 | static class BaseWithProperties { |
22 | 47 | public String entityName; |
@@ -136,8 +161,25 @@ public Map<String, Object> getSecondProperties() { |
136 | 161 | } |
137 | 162 | } |
138 | 163 |
|
| 164 | + /* |
| 165 | + /********************************************************************** |
| 166 | + /* Test methods |
| 167 | + /********************************************************************** |
| 168 | + */ |
| 169 | + |
139 | 170 | private final ObjectMapper MAPPER = newJsonMapper(); |
140 | 171 |
|
| 172 | + // For [databind#518] |
| 173 | + @Test |
| 174 | + void anyBeanWithSort518() throws Exception |
| 175 | + { |
| 176 | + Map<String,Object> extra = new LinkedHashMap<>(); |
| 177 | + extra.put("y", 4); |
| 178 | + extra.put("x", 3); |
| 179 | + String json = MAPPER.writeValueAsString(new Bean518(2, 1, extra)); |
| 180 | + assertEquals(a2q("{'a':2,'b':1,'y':4,'x':3}"), json); |
| 181 | + } |
| 182 | + |
141 | 183 | // For [databind#4388] |
142 | 184 | @Test |
143 | 185 | public void testSerializationOrderVersion1() throws Exception { |
|
0 commit comments