Skip to content

Commit a1744ad

Browse files
authored
Merge pull request #224 from FasterXML/tatu/2.16/223-add-failing-test
Add test for #223: passes for Blackbird, fails for Afterburner
2 parents af6f4c0 + 9a51cb9 commit a1744ad

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ syntax: glob
1010
# building
1111
target
1212
.mvn/wrapper/maven-wrapper.jar
13+
dependency-reduced-pom.xml
1314

1415
# Eclipse
1516
.classpath
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.fasterxml.jackson.module.afterburner.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import com.fasterxml.jackson.module.afterburner.AfterburnerTestBase;
6+
7+
// for [modules-base#223]
8+
public class DefaultMethods223Test extends AfterburnerTestBase
9+
{
10+
interface Animal223 {
11+
public String getName();
12+
13+
public void setName(String name);
14+
default public String getInfo() {
15+
return "";
16+
}
17+
18+
// Problematic case:
19+
default public void setInfo(String info) { }
20+
}
21+
22+
@JsonPropertyOrder({ "name", "info" })
23+
static class Cat223 implements Animal223 {
24+
String name;
25+
26+
@Override
27+
public String getName() {
28+
return name;
29+
}
30+
31+
@Override
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
}
36+
37+
/*
38+
/**********************************************************************
39+
/* Test methods
40+
/**********************************************************************
41+
*/
42+
43+
private final ObjectMapper MAPPER = newObjectMapper();
44+
45+
public void testSerializeViaDefault223() throws Exception
46+
{
47+
Cat223 cat = new Cat223();
48+
cat.setName("Molly");
49+
assertEquals(a2q("{'name':'Molly','info':''}"),
50+
MAPPER.writeValueAsString(cat));
51+
}
52+
53+
public void testDeserializeViaDefault223() throws Exception
54+
{
55+
String json = a2q("{'name':'Emma','info':'xyz'}");
56+
Cat223 cat = MAPPER.readValue(json, Cat223.class);
57+
assertEquals("Emma", cat.getName());
58+
assertEquals("", cat.getInfo());
59+
}
60+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.fasterxml.jackson.module.blackbird.deser.java8;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import com.fasterxml.jackson.module.blackbird.BlackbirdTestBase;
7+
8+
// for [modules-base#223]
9+
public class DefaultMethods223Test extends BlackbirdTestBase
10+
{
11+
interface Animal223 {
12+
public String getName();
13+
14+
public void setName(String name);
15+
default public String getInfo() {
16+
return "";
17+
}
18+
19+
// Problematic case:
20+
default public void setInfo(String info) { }
21+
}
22+
23+
@JsonPropertyOrder({ "name", "info" })
24+
static class Cat223 implements Animal223 {
25+
String name;
26+
27+
@Override
28+
public String getName() {
29+
return name;
30+
}
31+
32+
@Override
33+
public void setName(String name) {
34+
this.name = name;
35+
}
36+
}
37+
38+
/*
39+
/**********************************************************************
40+
/* Test methods
41+
/**********************************************************************
42+
*/
43+
44+
private final ObjectMapper MAPPER = newObjectMapper();
45+
46+
public void testSerializeViaDefault223() throws Exception
47+
{
48+
Cat223 cat = new Cat223();
49+
cat.setName("Molly");
50+
assertEquals(a2q("{'name':'Molly','info':''}"),
51+
MAPPER.writeValueAsString(cat));
52+
}
53+
54+
public void testDeserializeViaDefault223() throws Exception
55+
{
56+
String json = a2q("{'name':'Emma','info':'xyz'}");
57+
Cat223 cat = MAPPER.readValue(json, Cat223.class);
58+
assertEquals("Emma", cat.getName());
59+
assertEquals("", cat.getInfo());
60+
}
61+
}

0 commit comments

Comments
 (0)