Skip to content

Commit 89dbc90

Browse files
authored
Merge pull request #31 from lpandzic/#1631
added test for new feature in #1631
2 parents 7b0f287 + 582e142 commit 89dbc90

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

parameter-names/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ introspection of method/constructor parameter names, without having to add expli
2121
<packageVersion.dir>com/fasterxml/jackson/module/paramnames</packageVersion.dir>
2222
<packageVersion.package>${project.groupId}.paramnames</packageVersion.package>
2323

24-
<assertj-core.version>3.4.0</assertj-core.version>
24+
<assertj-core.version>3.8.0</assertj-core.version>
2525
<mockito-core.version>1.10.19</mockito-core.version>
2626
</properties>
2727

parameter-names/src/test/java/com/fasterxml/jackson/module/paramnames/JsonCreatorTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.fasterxml.jackson.databind.*;
55
import org.junit.*;
66

7+
import java.io.IOException;
8+
79
import static org.assertj.core.api.BDDAssertions.*;
810

911
public class JsonCreatorTest
@@ -23,6 +25,21 @@ public void shouldDeserializeClassWithJsonCreatorOnStaticMethod() throws Excepti
2325
then(actual).isEqualToComparingFieldByField(new ClassWithJsonCreatorOnStaticMethod("1st", "2nd"));
2426
}
2527

28+
@Test
29+
public void shouldDeserializeUsingDefaultPropertyCreatorSetting() throws IOException {
30+
// given
31+
ObjectMapper objectMapper = new ObjectMapper();
32+
objectMapper.registerModule(new ParameterNamesModule());
33+
objectMapper.configure(MapperFeature.SET_PROPERTY_CREATOR_AS_DEFAULT, true);
34+
int givenValue = 1;
35+
36+
// when
37+
SinglePropertyValueClass actual = objectMapper.readValue("{\"value\":\"" + givenValue + "\"}",
38+
SinglePropertyValueClass.class);
39+
// then
40+
then(actual).isEqualToComparingFieldByField(new SinglePropertyValueClass(givenValue));
41+
}
42+
2643
static class ClassWithJsonCreatorOnStaticMethod {
2744
final String first;
2845
final String second;
@@ -38,4 +55,16 @@ static ClassWithJsonCreatorOnStaticMethod factory(String first, String second) {
3855
return new ClassWithJsonCreatorOnStaticMethod(first, second);
3956
}
4057
}
58+
59+
static class SinglePropertyValueClass {
60+
private final Integer value;
61+
62+
SinglePropertyValueClass(Integer value) {
63+
this.value = value;
64+
}
65+
66+
public Integer getValue() {
67+
return value;
68+
}
69+
}
4170
}

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<dependency>
4646
<groupId>com.fasterxml.jackson.core</groupId>
4747
<artifactId>jackson-databind</artifactId>
48+
<version>2.9.0-SNAPSHOT</version>
4849
</dependency>
4950

5051
<dependency> <!-- all modules use junit for testing -->

0 commit comments

Comments
 (0)