Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit f06596a

Browse files
committed
removed override of json creator mode
1 parent 71ed648 commit f06596a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/main/java/com/fasterxml/jackson/module/paramnames/ParameterNamesAnnotationIntrospector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public String findImplicitPropertyName(AnnotatedMember m) {
3636
@Override
3737
public JsonCreator.Mode findCreatorBinding(Annotated a) {
3838

39+
JsonCreator ann = a.getAnnotation(JsonCreator.class);
40+
if (ann != null) {
41+
return ann.mode();
42+
}
43+
3944
return creatorBinding;
4045
}
4146

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fasterxml.jackson.module.paramnames;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import org.junit.Test;
6+
7+
import java.io.IOException;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
11+
import static org.assertj.core.api.BDDAssertions.then;
12+
13+
public class DelegatingCreatorTest {
14+
15+
@Test
16+
public void shouldNotOverrideJsonCreatorAnnotationWithSpecifiedMode() throws IOException {
17+
18+
// given
19+
ObjectMapper objectMapper = new ObjectMapper();
20+
objectMapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
21+
22+
// when
23+
ClassWithDelegatingCreator actual = objectMapper.readValue("{\"value\":\"aValue\"}", ClassWithDelegatingCreator.class);
24+
25+
// then
26+
Map<String, String> props = new HashMap<>();
27+
props.put("value", "aValue");
28+
ClassWithDelegatingCreator expected = new ClassWithDelegatingCreator(props);
29+
then(actual).isEqualToComparingFieldByField(expected);
30+
}
31+
32+
static class ClassWithDelegatingCreator {
33+
34+
private final String value;
35+
36+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
37+
ClassWithDelegatingCreator(Map<String, String> props) {
38+
this.value = props.get("value");
39+
}
40+
41+
String getValue() {
42+
return value;
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)