Skip to content

Commit d33533c

Browse files
lpandzicWellingR
authored andcommitted
added test for new feature in #1631
1 parent ae6b8e0 commit d33533c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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
@@ -22,6 +24,21 @@ public void shouldDeserializeClassWithJsonCreatorOnStaticMethod() throws Excepti
2224
then(actual).isEqualToComparingFieldByField(new ClassWithJsonCreatorOnStaticMethod("1st", "2nd"));
2325
}
2426

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

0 commit comments

Comments
 (0)