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

Commit 71ed648

Browse files
committed
Merge pull request #2 from FasterXML/master
Merge upstream
2 parents f8303ae + 6919787 commit 71ed648

File tree

7 files changed

+80
-21
lines changed

7 files changed

+80
-21
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
<parent>
55
<groupId>com.fasterxml.jackson</groupId>
66
<artifactId>jackson-parent</artifactId>
7-
<version>2.5.1</version>
7+
<version>2.6.1</version>
88
</parent>
99
<groupId>com.fasterxml.jackson.module</groupId>
1010
<artifactId>jackson-module-parameter-names</artifactId>
1111
<name>Jackson-module-parameter-names</name>
12-
<version>2.6.0-rc3-SNAPSHOT</version>
12+
<version>2.6.1-SNAPSHOT</version>
1313
<packaging>bundle</packaging>
1414
<description>Add-on module for Jackson (http://jackson.codehaus.org) to support
1515
introspection of method/constructor parameter names, without having to add explicit property name annotation.
@@ -30,7 +30,7 @@ introspection of method/constructor parameter names, without having to add expli
3030
<tag>HEAD</tag>
3131
</scm>
3232
<properties>
33-
<version.jackson.core>2.6.0-rc2</version.jackson.core>
33+
<version.jackson.core>2.6.0</version.jackson.core>
3434
<!-- explicitly target JDK 8 -->
3535
<javac.src.version>1.8</javac.src.version>
3636
<javac.target.version>1.8</javac.target.version>

release-notes/VERSION

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Project: jackson-module-parameter-names
44
= Releases
55
------------------------------------------------------------------------
66

7+
2.6.0 (19-Jul-2015)
8+
9+
#21: Unable to associate parameter name with single non-annotated constructor argument
10+
(reported by Michael H, michaelhixson@github)
11+
12+
2.5.4 (09-Jun-2015)
713
2.5.3 (24-Apr-2015)
814
2.5.2 (29-Mar-2015)
915
2.5.1 (06-Feb-2015)

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
package com.fasterxml.jackson.module.paramnames;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
34
import com.fasterxml.jackson.databind.AnnotationIntrospector;
45
import com.fasterxml.jackson.databind.introspect.*;
56

67
import java.lang.reflect.*;
78

89
/**
9-
* Introspector that uses parameter name information provided by the Java Reflection API additions in Java 8 to determine the parameter
10-
* name for methods and constructors.
10+
* Introspector that uses parameter name information provided by the Java Reflection API additions in Java 8 to
11+
* determine the parameter name for methods and constructors.
1112
*
1213
* @author Lovro Pandzic
1314
* @see AnnotationIntrospector
1415
* @see Parameter
1516
*/
1617
class ParameterNamesAnnotationIntrospector extends NopAnnotationIntrospector
1718
{
18-
// stateless, can just use static id
1919
private static final long serialVersionUID = 1L;
2020

21-
/**
22-
* Since Jackson 2.4, there has been distinction between annotation-specified
23-
* explicit names; and implicit name that comes from source.
24-
*/
25-
/*
26-
@Override
27-
public PropertyName findNameForDeserialization(Annotated annotated) {
28-
return null;
21+
private final JsonCreator.Mode creatorBinding;
22+
23+
ParameterNamesAnnotationIntrospector(JsonCreator.Mode creatorBinding) {
24+
25+
this.creatorBinding = creatorBinding;
2926
}
30-
*/
3127

32-
// since 2.4
3328
@Override
3429
public String findImplicitPropertyName(AnnotatedMember m) {
3530
if (m instanceof AnnotatedParameter) {
@@ -38,6 +33,12 @@ public String findImplicitPropertyName(AnnotatedMember m) {
3833
return null;
3934
}
4035

36+
@Override
37+
public JsonCreator.Mode findCreatorBinding(Annotated a) {
38+
39+
return creatorBinding;
40+
}
41+
4142
/**
4243
* Returns the parameter name, or {@code null} if it could not be determined.
4344
*
@@ -49,7 +50,7 @@ private String findParameterName(AnnotatedParameter annotatedParameter) {
4950

5051
AnnotatedWithParams owner = annotatedParameter.getOwner();
5152
Parameter[] params;
52-
53+
5354
if (owner instanceof AnnotatedConstructor) {
5455
params = ((AnnotatedConstructor) owner).getAnnotated().getParameters();
5556
} else if (owner instanceof AnnotatedMethod) {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
package com.fasterxml.jackson.module.paramnames;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
34
import com.fasterxml.jackson.core.json.PackageVersion;
45
import com.fasterxml.jackson.databind.module.SimpleModule;
56

67
public class ParameterNamesModule extends SimpleModule
78
{
89
private static final long serialVersionUID = 1L;
910

10-
public ParameterNamesModule()
11-
{
11+
private final JsonCreator.Mode creatorBinding;
12+
13+
public ParameterNamesModule(JsonCreator.Mode creatorBinding) {
14+
super(PackageVersion.VERSION);
15+
this.creatorBinding = creatorBinding;
16+
}
17+
18+
public ParameterNamesModule() {
1219
super(PackageVersion.VERSION);
20+
this.creatorBinding = null;
1321
}
1422

1523
@Override
1624
public void setupModule(SetupContext context) {
1725
super.setupModule(context);
18-
context.insertAnnotationIntrospector(new ParameterNamesAnnotationIntrospector());
26+
context.insertAnnotationIntrospector(new ParameterNamesAnnotationIntrospector(creatorBinding));
1927
}
2028

2129
@Override

src/test/java/com/fasterxml/jackson/module/paramnames/ParameterNamesAnnotationIntrospectorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.module.paramnames;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
34
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor;
45
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
56
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
@@ -16,7 +17,7 @@
1617
*/
1718
public class ParameterNamesAnnotationIntrospectorTest {
1819

19-
private final ParameterNamesAnnotationIntrospector PN_AI = new ParameterNamesAnnotationIntrospector();
20+
private final ParameterNamesAnnotationIntrospector PN_AI = new ParameterNamesAnnotationIntrospector(JsonCreator.Mode.DEFAULT);
2021

2122
@Test
2223
public void shouldFindParameterNameFromConstructorForLegalIndex() throws Exception {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.fasterxml.jackson.module.paramnames;
2+
3+
public class SimplePerson {
4+
5+
private final String name;
6+
7+
public SimplePerson(String name) {
8+
9+
this.name = name;
10+
}
11+
12+
public String getName() {
13+
14+
return name;
15+
}
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.annotation.JsonCreator;
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import org.junit.Test;
10+
11+
public class SimplePersonTest {
12+
13+
@Test
14+
public void shouldBeAbleToDeserializeSimplePerson() throws IOException {
15+
16+
// given
17+
ObjectMapper objectMapper = new ObjectMapper();
18+
objectMapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
19+
20+
// when
21+
SimplePerson actual = objectMapper.readValue("{\"name\":\"joe\"}", SimplePerson.class);
22+
23+
// then
24+
SimplePerson expected = new SimplePerson("joe");
25+
then(actual).isEqualToComparingFieldByField(expected);
26+
}
27+
}

0 commit comments

Comments
 (0)