Skip to content

Commit

Permalink
Merge pull request #31 from lpandzic/#1631
Browse files Browse the repository at this point in the history
added test for new feature in #1631
  • Loading branch information
cowtowncoder authored Jun 7, 2017
2 parents 7b0f287 + 582e142 commit 89dbc90
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parameter-names/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ introspection of method/constructor parameter names, without having to add expli
<packageVersion.dir>com/fasterxml/jackson/module/paramnames</packageVersion.dir>
<packageVersion.package>${project.groupId}.paramnames</packageVersion.package>

<assertj-core.version>3.4.0</assertj-core.version>
<assertj-core.version>3.8.0</assertj-core.version>
<mockito-core.version>1.10.19</mockito-core.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.fasterxml.jackson.databind.*;
import org.junit.*;

import java.io.IOException;

import static org.assertj.core.api.BDDAssertions.*;

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

@Test
public void shouldDeserializeUsingDefaultPropertyCreatorSetting() throws IOException {
// given
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new ParameterNamesModule());
objectMapper.configure(MapperFeature.SET_PROPERTY_CREATOR_AS_DEFAULT, true);
int givenValue = 1;

// when
SinglePropertyValueClass actual = objectMapper.readValue("{\"value\":\"" + givenValue + "\"}",
SinglePropertyValueClass.class);
// then
then(actual).isEqualToComparingFieldByField(new SinglePropertyValueClass(givenValue));
}

static class ClassWithJsonCreatorOnStaticMethod {
final String first;
final String second;
Expand All @@ -38,4 +55,16 @@ static ClassWithJsonCreatorOnStaticMethod factory(String first, String second) {
return new ClassWithJsonCreatorOnStaticMethod(first, second);
}
}

static class SinglePropertyValueClass {
private final Integer value;

SinglePropertyValueClass(Integer value) {
this.value = value;
}

public Integer getValue() {
return value;
}
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0-SNAPSHOT</version>
</dependency>

<dependency> <!-- all modules use junit for testing -->
Expand Down

0 comments on commit 89dbc90

Please sign in to comment.