Skip to content

Commit 9b363bf

Browse files
committed
Add a failing test for #178
1 parent 05893c5 commit 9b363bf

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,37 @@
22

33
import com.fasterxml.jackson.annotation.*;
44
import com.fasterxml.jackson.databind.*;
5+
56
import org.junit.*;
67

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

9-
public class JsonCreatorTest
10+
public class JsonCreatorTest extends ModuleTestBase
1011
{
11-
@Test
12-
public void shouldDeserializeClassWithJsonCreatorOnStaticMethod() throws Exception {
13-
14-
// given
15-
ObjectMapper objectMapper = new ObjectMapper();
16-
objectMapper.registerModule(new ParameterNamesModule());
17-
12+
static class ClassWithJsonCreatorOnStaticMethod {
13+
final String first;
14+
final String second;
15+
16+
ClassWithJsonCreatorOnStaticMethod(String first, String second) {
17+
this.first = first;
18+
this.second = second;
19+
}
20+
21+
@JsonCreator
22+
static ClassWithJsonCreatorOnStaticMethod factory(String first, String second) {
23+
return new ClassWithJsonCreatorOnStaticMethod(first, second);
24+
}
25+
}
26+
27+
private final ObjectMapper MAPPER = newMapper();
28+
29+
@Test
30+
public void testJsonCreatorOnStaticMethod() throws Exception
31+
{
1832
// when
19-
String json = "{\"first\":\"1st\",\"second\":\"2nd\"}";
20-
ClassWithJsonCreatorOnStaticMethod actual = objectMapper.readValue(json, ClassWithJsonCreatorOnStaticMethod.class);
33+
String json = a2q("{'first':'1st','second':'2nd'}");
34+
ClassWithJsonCreatorOnStaticMethod actual = MAPPER.readValue(json, ClassWithJsonCreatorOnStaticMethod.class);
2135

2236
then(actual).isEqualToComparingFieldByField(new ClassWithJsonCreatorOnStaticMethod("1st", "2nd"));
23-
}
24-
25-
static class ClassWithJsonCreatorOnStaticMethod {
26-
final String first;
27-
final String second;
28-
29-
ClassWithJsonCreatorOnStaticMethod(String first, String second) {
30-
this.first = first;
31-
this.second = second;
32-
}
33-
34-
@JsonCreator
35-
static ClassWithJsonCreatorOnStaticMethod factory(String first, String second) {
36-
37-
return new ClassWithJsonCreatorOnStaticMethod(first, second);
38-
}
39-
}
37+
}
4038
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ protected static JsonMapper.Builder mapperBuilder() {
1717
.addModule(new ParameterNamesModule());
1818
}
1919

20-
protected String quote(String value) {
20+
protected String q(String value) {
2121
return "\"" + value + "\"";
2222
}
2323

24-
protected String aposToQuotes(String json) {
24+
protected String a2q(String json) {
2525
return json.replace("'", "\"");
2626
}
2727

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.module.paramnames.failing;
2+
3+
import com.fasterxml.jackson.databind.*;
4+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
5+
import com.fasterxml.jackson.module.paramnames.ModuleTestBase;
6+
7+
import org.junit.*;
8+
9+
import static org.junit.Assert.assertNotNull;
10+
11+
public class JsonCreator178Test extends ModuleTestBase
12+
{
13+
// [modules-base#178]
14+
static class Bean178
15+
{
16+
int _a, _b;
17+
18+
public Bean178(@JsonDeserialize() int a, int b) {
19+
_a = a;
20+
_b = b;
21+
}
22+
}
23+
24+
private final ObjectMapper MAPPER = newMapper();
25+
26+
// [modules-base#178]
27+
@Test
28+
public void testJsonCreatorWithOtherAnnotations() throws Exception
29+
{
30+
Bean178 bean = MAPPER.readValue(a2q("{'a':1,'b':2}"), Bean178.class);
31+
assertNotNull(bean);
32+
}
33+
}

0 commit comments

Comments
 (0)