|
| 1 | +package com.fasterxml.jackson.databind.deser.creators; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import com.fasterxml.jackson.annotation.JsonCreator; |
| 6 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 7 | + |
| 8 | +import com.fasterxml.jackson.databind.*; |
| 9 | +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; |
| 10 | +import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.fail; |
| 13 | + |
| 14 | +public class CreatorWithRenamedParam4545Test |
| 15 | + extends DatabindTestUtil |
| 16 | +{ |
| 17 | + static class Payload4545 { |
| 18 | + private final String key1; |
| 19 | + private final String key2; |
| 20 | + |
| 21 | + @JsonCreator |
| 22 | + public Payload4545( |
| 23 | + @ImplicitName("key1") |
| 24 | + @JsonProperty("key") |
| 25 | + String key1, // NOTE: the mismatch `key` / `key1` is important |
| 26 | + |
| 27 | + @ImplicitName("key2") |
| 28 | + @JsonProperty("key2") |
| 29 | + String key2 |
| 30 | + ) { |
| 31 | + this.key1 = key1; |
| 32 | + this.key2 = key2; |
| 33 | + } |
| 34 | + |
| 35 | + public String getKey1() { |
| 36 | + return key1; |
| 37 | + } |
| 38 | + |
| 39 | + public String getKey2() { |
| 40 | + return key2; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private final ObjectMapper MAPPER = jsonMapperBuilder() |
| 45 | + .disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) |
| 46 | + .annotationIntrospector(new ImplicitNameIntrospector()) |
| 47 | + .build(); |
| 48 | + |
| 49 | + // [databind#4545] |
| 50 | + @Test |
| 51 | + public void testCreatorWithRename4545() throws Exception |
| 52 | + { |
| 53 | + String jsonPayload = a2q("{ 'key1': 'val1', 'key2': 'val2'}"); |
| 54 | + |
| 55 | + try { |
| 56 | + MAPPER.readValue(jsonPayload, Payload4545.class); |
| 57 | + fail("Should not pass"); |
| 58 | + } catch (UnrecognizedPropertyException e) { |
| 59 | + verifyException(e, "Unrecognized"); |
| 60 | + verifyException(e, "key1"); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments