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

Commit 05bc1fa

Browse files
committed
Fix #25 for 2.4[.7] for lark
1 parent 0cb4200 commit 05bc1fa

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Project: jackson-module-mrbean
66

77
2.5.0 (not yet released)
88

9+
2.4.67 (not released -- may or may not be released)
10+
11+
#25: Should ignore `static` methods (setter/getter)
12+
913
2.4.6 (23-Apr-2015)
1014
2.4.5 (13-Jan-2015)
1115
2.4.4 (24-Nov-2014)

src/main/java/com/fasterxml/jackson/module/mrbean/BeanBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.objectweb.asm.Type;
99

1010
import java.lang.reflect.Method;
11+
import java.lang.reflect.Modifier;
1112
import java.util.ArrayList;
1213
import java.util.LinkedHashMap;
1314
import java.util.Map;
@@ -59,9 +60,13 @@ public BeanBuilder implement(boolean failOnUnrecognized)
5960
for (Class<?> impl : implTypes) {
6061
// and then find all getters, setters, and other non-concrete methods therein:
6162
for (Method m : impl.getDeclaredMethods()) {
63+
// 15-Sep-2015, tatu: As per [module-mrbean#25], make sure to ignore static
64+
// methods.
65+
if (Modifier.isStatic(m.getModifiers())) {
66+
continue;
67+
}
6268
String methodName = m.getName();
6369
int argCount = m.getParameterTypes().length;
64-
6570
if (argCount == 0) { // getter?
6671
if (methodName.startsWith("get") || methodName.startsWith("is") && returnsBoolean(m)) {
6772
addGetter(m);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.fasterxml.jackson.module.mrbean;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
5+
/**
6+
* Test(s) to ensure that `static` methods are not considered to be
7+
* accessors.
8+
* Specifically, test for [module-mrbean#25]
9+
*/
10+
public class TestStaticMethods extends BaseTest
11+
{
12+
static class TestPOJO
13+
{
14+
public AbstractRoot root;
15+
16+
public void setRoot(AbstractRoot root) {
17+
this.root = root;
18+
}
19+
20+
public AbstractRoot getRoot() {
21+
return root;
22+
}
23+
}
24+
25+
public static class Root extends AbstractRoot {
26+
public Root() {}
27+
}
28+
29+
public static abstract class AbstractRoot
30+
{
31+
static Leaf leaf;
32+
33+
private int x;
34+
35+
public AbstractRoot() {}
36+
37+
// bogus: being static, ought to be skipped
38+
public static void setLeaf(Leaf leaf) {
39+
AbstractRoot.leaf = leaf;
40+
}
41+
42+
public int getX() {
43+
return x;
44+
}
45+
46+
public void setX(int x) {
47+
this.x = x;
48+
}
49+
}
50+
51+
//Bad jackson class, to generate the IllegalArgumentException
52+
//This class should be ignored by Jackson
53+
static class Leaf
54+
{
55+
public String test;
56+
57+
public void setTest(String test) {
58+
this.test = test;
59+
}
60+
61+
public void setTest(StringBuilder test) {
62+
this.test = test.toString();
63+
}
64+
}
65+
66+
public void testAbstract25() throws Exception
67+
{
68+
TestPOJO v = new TestPOJO();
69+
70+
Root root = new Root();
71+
root.setX(2);
72+
73+
v.setRoot(root);
74+
75+
ObjectMapper mapper = new ObjectMapper();
76+
mapper.registerModule(new MrBeanModule());
77+
String jsonValue = mapper.writeValueAsString(v);
78+
79+
TestPOJO result = mapper.readValue(jsonValue, TestPOJO.class);
80+
assertNotNull(result);
81+
}
82+
}

0 commit comments

Comments
 (0)