Skip to content

Commit 3146384

Browse files
committed
Add failing test for #123
1 parent 40bc785 commit 3146384

File tree

3 files changed

+69
-34
lines changed

3 files changed

+69
-34
lines changed
+27-33
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import com.fasterxml.jackson.annotation.JsonProperty;
66
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
7+
78
import com.fasterxml.jackson.databind.ObjectMapper;
9+
810
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
911

10-
public class TestSimpleDeserialize extends AfterburnerTestBase
12+
public class BasicDeserializeTest extends AfterburnerTestBase
1113
{
1214
public enum MyEnum {
1315
A, B, C;
@@ -143,6 +145,23 @@ static class Issue60Pojo {
143145
public List<Object> foos;
144146
}
145147

148+
// [modules-base#123]: fluent method(s)
149+
public static class Model123 {
150+
int value = 10;
151+
152+
protected Model123() { }
153+
public Model123(int v) { value = v; }
154+
155+
public int getValue() {
156+
return value;
157+
}
158+
159+
public Model123 setValue(int value) {
160+
this.value = value;
161+
return this;
162+
}
163+
}
164+
146165
/*
147166
/**********************************************************************
148167
/* Test methods, method access
@@ -325,38 +344,13 @@ public void testProblemWithIndentation() throws Exception {
325344
assertEquals(0, pojo.foos.size());
326345
}
327346

328-
// 28-Sep-2019, tatu: I do not fully understand what this method tried to do;
329-
// it seemed to be a contribution from July 2016. But I noticed that it breaks
330-
// with JDK 12 and unlikely to be allowed so let's comment it out.
331-
/*
347+
// [modules-base#123]
348+
public void testFluentMethod() throws Exception
349+
{
350+
String json = MAPPER.writeValueAsString(new Model123(28));
332351

333-
static class CheckGeneratedDeserializerName {
334-
public String stringField;
335-
}
336-
337-
@SuppressWarnings("unchecked")
338-
public void testGeneratedDeserializerName() throws Exception {
339-
MAPPER.readValue("{\"stringField\":\"foo\"}", CheckGeneratedDeserializerName.class);
340-
ClassLoader cl = getClass().getClassLoader();
341-
Field declaredField = ClassLoader.class.getDeclaredField("classes");
342-
declaredField.setAccessible(true);
343-
// 06-Sep-2017, tatu: Hmmh. Whatever this code does... is not very robust.
344-
// But has to do for now. OpenJDK 7 had issues with size, increased:
345-
Class<?>[] os = new Class[8192];
346-
((Vector<Class<?>>) declaredField.get(cl)).copyInto(os);
347-
348-
String expectedClassName = TestSimpleDeserialize.class.getCanonicalName()
349-
+ "$CheckGeneratedDeserializerName$Access4JacksonDeserializer";
350-
for (Class<?> clz : os) {
351-
if (clz == null) {
352-
break;
353-
}
354-
if (clz.getCanonicalName() != null
355-
&& clz.getCanonicalName().startsWith(expectedClassName)) {
356-
return;
357-
}
358-
}
359-
fail("Expected class not found:" + expectedClassName);
352+
Model123 result = MAPPER.readValue(json, Model123.class);
353+
assertNotNull(result);
354+
assertEquals(28, result.value);
360355
}
361-
*/
362356
}

blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/deser/TestSimpleDeserialize.java renamed to blackbird/src/test/java/com/fasterxml/jackson/module/blackbird/deser/BasicDeserializeTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.fasterxml.jackson.module.blackbird.deser;
22

33
import java.util.List;
4+
45
import com.fasterxml.jackson.annotation.JsonProperty;
56
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
7+
68
import com.fasterxml.jackson.databind.ObjectMapper;
9+
710
import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;
811

9-
public class TestSimpleDeserialize extends BlackbirdTestBase
12+
public class BasicDeserializeTest extends BlackbirdTestBase
1013
{
1114
public enum MyEnum {
1215
A, B, C;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fasterxml.jackson.module.blackbird.failing;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
5+
import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;
6+
7+
// Failing test from "BasicDeserializeTest", see [modules-base#123]
8+
public class BasicDeserialize123Test extends BlackbirdTestBase
9+
{
10+
// [modules-base#123]: fluent method(s)
11+
static class Model123 {
12+
int value = 10;
13+
14+
protected Model123() { }
15+
public Model123(int v) { value = v; }
16+
17+
public int getValue() {
18+
return value;
19+
}
20+
21+
public Model123 setValue(int value) {
22+
this.value = value;
23+
return this;
24+
}
25+
}
26+
27+
private final ObjectMapper MAPPER = newObjectMapper();
28+
29+
// [modules-base#123]
30+
public void testFluentMethod() throws Exception
31+
{
32+
String json = MAPPER.writeValueAsString(new Model123(28));
33+
34+
Model123 result = MAPPER.readValue(json, Model123.class);
35+
assertNotNull(result);
36+
assertEquals(28, result.value);
37+
}
38+
}

0 commit comments

Comments
 (0)