Skip to content

Commit

Permalink
Add a passing test for #4545
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 31, 2024
1 parent c524eae commit 296d90c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1791,3 +1791,8 @@ Teodor Danciu (teodord@github)
Matthew Luckam (mluckam@github)
* Contributed #4483: Remove `final` on method BeanSerializer.serialize()
(2.18.0)

Alexandre Jacob (ajacob@github)
* Reported #4545: Unexpected deserialization behavior with `@JsonCreator`,
`@JsonProperty` and javac `-parameters`
(2.18.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Project: jackson-databind
#4483: Remove `final` on method BeanSerializer.serialize()
(contributed by Matthew L)
#4515: Rewrite Bean Property Introspection logic in Jackson 2.x
#4545: Unexpected deserialization behavior with `@JsonCreator`,
`@JsonProperty` and javac `-parameters`
(reported by Alexandre J)

2.17.1 (04-May-2024)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.fasterxml.jackson.databind.deser.creators;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.fail;

public class CreatorWithRenamedParam4545Test
extends DatabindTestUtil
{
static class Payload4545 {
private final String key1;
private final String key2;

@JsonCreator
public Payload4545(
@ImplicitName("key1")
@JsonProperty("key")
String key1, // NOTE: the mismatch `key` / `key1` is important

@ImplicitName("key2")
@JsonProperty("key2")
String key2
) {
this.key1 = key1;
this.key2 = key2;
}

public String getKey1() {
return key1;
}

public String getKey2() {
return key2;
}
}

private final ObjectMapper MAPPER = jsonMapperBuilder()
.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS)
.annotationIntrospector(new ImplicitNameIntrospector())
.build();

// [databind#4545]
@Test
public void testCreatorWithRename4545() throws Exception
{
String jsonPayload = a2q("{ 'key1': 'val1', 'key2': 'val2'}");

try {
MAPPER.readValue(jsonPayload, Payload4545.class);
fail("Should not pass");
} catch (UnrecognizedPropertyException e) {
verifyException(e, "Unrecognized");
verifyException(e, "key1");
}
}
}

0 comments on commit 296d90c

Please sign in to comment.