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

Commit 12bb5ee

Browse files
committed
Merge pull request #17 from lpandzic/issue-13-readme.md
issue-13 readme md update
2 parents ae9e952 + bf6caec commit 12bb5ee

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ So, after registering the module as described above, you will be able to use dat
3535
```java
3636
class Person {
3737

38+
// mandatory fields
3839
private final String name;
3940
private final String surname;
41+
42+
// optional fields
43+
private String nickname;
4044

41-
@JsonCreator // important!
45+
// no annotations are required if preconditions are met (details below)
4246
public Person(String name, String surname) {
4347

4448
this.name = name;
@@ -52,14 +56,27 @@ class Person {
5256
public String getSurname() {
5357
return surname;
5458
}
59+
60+
public String getNickname() {
61+
62+
return nickname;
63+
}
64+
65+
public void setNickname(String nickname) {
66+
67+
this.nickname = nickname;
68+
}
5569
}
5670
```
57-
class Person must be compiled with Java 8 compliant compiler with the enabled option to store formal parameter names (`-parameters` option). For more information about Java 8 API for accessing parameter names at runtime see [this][2].
5871

72+
Preconditions:
73+
74+
- class Person must be compiled with Java 8 compliant compiler with option to store formal parameter names turned on (`-parameters` option). For more information about Java 8 API for accessing parameter names at runtime see [this][2]
75+
- if there are multiple visible constructors and there is no default constructor, @JsonCreator is required to select constructor for deserialization
5976

6077
## More
6178

6279
See [Wiki](../../wiki) for more information (javadocs, downloads).
6380

6481
[1]: http://jackson.codehaus.org/1.1.2/javadoc/org/codehaus/jackson/annotate/JsonProperty.html
65-
[2]: http://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html
82+
[2]: http://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ introspection of method/constructor parameter names, without having to add expli
3737
<!-- Generate PackageVersion.java into this directory. -->
3838
<packageVersion.dir>com/fasterxml/jackson/module/paramnames</packageVersion.dir>
3939
<packageVersion.package>${project.groupId}.paramnames</packageVersion.package>
40-
<assertj-core.version>1.7.1</assertj-core.version>
40+
<assertj-core.version>2.0.0</assertj-core.version>
4141

4242
<!-- Configuration properties for the OSGi maven-bundle-plugin -->
4343
<osgi.import>com.fasterxml.jackson.core
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fasterxml.jackson.module.paramnames;
2+
3+
class Person {
4+
5+
// mandatory fields
6+
private final String name;
7+
private final String surname;
8+
9+
// optional fields
10+
private String nickname;
11+
12+
// no annotations are required if preconditions are met (details below)
13+
public Person(String name, String surname) {
14+
15+
this.name = name;
16+
this.surname = surname;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public String getSurname() {
24+
return surname;
25+
}
26+
27+
public String getNickname() {
28+
29+
return nickname;
30+
}
31+
32+
public void setNickname(String nickname) {
33+
34+
this.nickname = nickname;
35+
}
36+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fasterxml.jackson.module.paramnames;
2+
3+
import static org.assertj.core.api.BDDAssertions.then;
4+
5+
import java.io.IOException;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import org.junit.Test;
9+
10+
public class PersonTest {
11+
12+
@Test
13+
public void shouldBeAbleToDeserializePerson() throws IOException {
14+
15+
// given
16+
ObjectMapper objectMapper = new ObjectMapper();
17+
objectMapper.registerModule(new ParameterNamesModule());
18+
19+
// when
20+
Person actual = objectMapper.readValue("{\"name\":\"joe\",\"surname\":\"smith\",\"nickname\":\"joey\"}", Person.class);
21+
22+
// then
23+
Person expected = new Person("joe", "smith");
24+
expected.setNickname("joey");
25+
then(actual).isEqualToComparingFieldByField(expected);
26+
27+
}
28+
}

0 commit comments

Comments
 (0)