|
3 | 3 | import org.junit.jupiter.api.Test;
|
4 | 4 |
|
5 | 5 | import com.fasterxml.jackson.annotation.JsonCreator;
|
| 6 | +import com.fasterxml.jackson.annotation.JsonPropertyOrder; |
6 | 7 | import com.fasterxml.jackson.annotation.JsonSetter;
|
7 | 8 | import com.fasterxml.jackson.annotation.Nulls;
|
8 | 9 |
|
@@ -139,9 +140,24 @@ public Boolean field() {
|
139 | 140 | return field;
|
140 | 141 | }
|
141 | 142 | }
|
142 |
| - |
| 143 | + |
| 144 | + // [databind#4860] |
| 145 | + @JsonPropertyOrder({ "id", "name "}) |
| 146 | + static class Foo4860 { |
| 147 | + public String id; |
| 148 | + public String name; |
| 149 | + |
| 150 | + public Foo4860() { } |
| 151 | + |
| 152 | + public Foo4860(String id) { |
| 153 | + // should not be called as of Jackson 2.x |
| 154 | + throw new IllegalStateException("Should not auto-detect args-taking constructor"); |
| 155 | + } |
| 156 | + } |
| 157 | + |
143 | 158 | private final ObjectMapper MAPPER_PROPS = mapperFor(ConstructorDetector.USE_PROPERTIES_BASED);
|
144 | 159 | private final ObjectMapper MAPPER_DELEGATING = mapperFor(ConstructorDetector.USE_DELEGATING);
|
| 160 | + private final ObjectMapper MAPPER_DEFAULT = mapperFor(ConstructorDetector.DEFAULT); |
145 | 161 | private final ObjectMapper MAPPER_EXPLICIT = mapperFor(ConstructorDetector.EXPLICIT_ONLY);
|
146 | 162 |
|
147 | 163 | private final ObjectMapper MAPPER_MUST_ANNOTATE = mapperFor(ConstructorDetector.DEFAULT
|
@@ -379,6 +395,42 @@ void nullHandlingCreator3241() throws Exception {
|
379 | 395 | }
|
380 | 396 | }
|
381 | 397 |
|
| 398 | + // [databind#4860] |
| 399 | + @Test |
| 400 | + public void testDeserialization4860PropsBased() throws Exception { |
| 401 | + _test4680With(MAPPER_PROPS); |
| 402 | + } |
| 403 | + |
| 404 | + @Test |
| 405 | + public void testDeserialization4860Delegating() throws Exception { |
| 406 | + _test4680With(MAPPER_DELEGATING); |
| 407 | + } |
| 408 | + |
| 409 | + @Test |
| 410 | + public void testDeserialization4860Default() throws Exception { |
| 411 | + _test4680With(MAPPER_DEFAULT); |
| 412 | + } |
| 413 | + |
| 414 | + @Test |
| 415 | + public void testDeserialization4860Explicit() throws Exception { |
| 416 | + _test4680With(MAPPER_EXPLICIT); |
| 417 | + } |
| 418 | + |
| 419 | + private void _test4680With(ObjectMapper mapper) throws Exception |
| 420 | + { |
| 421 | + _test4680With(mapper, "{}", a2q("{'id':null,'name':null}")); |
| 422 | + _test4680With(mapper, a2q("{'id':'something'}"), |
| 423 | + a2q("{'id':'something','name':null}")); |
| 424 | + _test4680With(mapper, a2q("{'id':'something','name':'name'}"), |
| 425 | + a2q("{'id':'something','name':'name'}")); |
| 426 | + } |
| 427 | + |
| 428 | + private void _test4680With(ObjectMapper mapper, String input, String output) throws Exception |
| 429 | + { |
| 430 | + Foo4860 result = mapper.readValue(input, Foo4860.class); |
| 431 | + assertEquals(output, mapper.writeValueAsString(result)); |
| 432 | + } |
| 433 | + |
382 | 434 | /*
|
383 | 435 | /**********************************************************************
|
384 | 436 | /* Helper methods
|
|
0 commit comments