Skip to content

Commit 8d05b09

Browse files
committed
Fix #42
1 parent 0900071 commit 8d05b09

File tree

5 files changed

+53
-12
lines changed

5 files changed

+53
-12
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ protected static int collectDefaults() {
7272

7373
/**
7474
* Default package to use for generated classes.
75-
*<p>
76-
* Note that before 2.6, defaulted to
77-
* "org.codehaus.jackson.generated.", changed as
78-
* per [mrbean#21]
7975
*/
8076
public final static String DEFAULT_PACKAGE_FOR_GENERATED = "com.fasterxml.jackson.module.mrbean.generated.";
8177

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,24 @@ public BeanBuilder implement(boolean failOnUnrecognized)
8383
String methodName = m.getName();
8484
int argCount = m.getParameterTypes().length;
8585
if (argCount == 0) { // getter?
86-
if (methodName.startsWith("get") || methodName.startsWith("is") && returnsBoolean(m)) {
87-
addGetter(ctxt, m);
86+
if (methodName.startsWith("get")) {
87+
if (methodName.length() > 3) { // ignore plain "get()"
88+
addGetter(ctxt, m);
89+
continue;
90+
}
91+
} else if (methodName.startsWith("is")) {
92+
if (methodName.length() > 2) { // ignore plain "is()"
93+
if (returnsBoolean(m)) {
94+
addGetter(ctxt, m);
95+
continue;
96+
}
97+
}
98+
}
99+
} else if ((argCount == 1) && methodName.startsWith("set")) { // ignore "set()"
100+
if (methodName.length() > 3) {
101+
addSetter(ctxt, m);
88102
continue;
89103
}
90-
} else if (argCount == 1 && methodName.startsWith("set")) {
91-
addSetter(ctxt, m);
92-
continue;
93104
}
94105
// Otherwise, if concrete, or already handled, skip:
95106
if (BeanUtil.isConcrete(m) || _unsupportedMethods.containsKey(methodName)) {

mrbean/src/test/java/com/fasterxml/jackson/module/mrbean/TestSimpleMaterializedInterfaces.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface PartialBean {
3636
public interface BeanHolder {
3737
public Bean getBean();
3838
}
39-
39+
4040
// then invalid one; conflicting setter/getter types
4141
public interface InvalidBean {
4242
public int getX();
@@ -184,11 +184,11 @@ public void testSubInterface() throws Exception
184184
*/
185185
public void testPartialBean() throws Exception
186186
{
187-
ObjectMapper mapper = new ObjectMapper();
188187
AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
189188
// ensure that we will only get deferred error methods
190189
mat.disable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
191-
mapper.registerModule(new MrBeanModule(mat));
190+
ObjectMapper mapper = new ObjectMapper()
191+
.registerModule(new MrBeanModule(mat));
192192
PartialBean bean = mapper.readValue("{\"ok\":true}", PartialBean.class);
193193
assertNotNull(bean);
194194
assertTrue(bean.isOk());

mrbean/src/test/java/com/fasterxml/jackson/module/mrbean/TestSimpleTypes.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.*;
44

55
import com.fasterxml.jackson.core.type.TypeReference;
6+
import com.fasterxml.jackson.databind.JsonMappingException;
67
import com.fasterxml.jackson.databind.ObjectMapper;
78

89
public class TestSimpleTypes extends BaseTest
@@ -20,6 +21,15 @@ public IntegerBean() { }
2021
public void setId(final Integer pId) { id = pId; }
2122
}
2223

24+
// for [modules-base#42]: ignore `get()` and `set()`
25+
public static interface JustGetAndSet {
26+
public int get();
27+
28+
public void set(int x);
29+
30+
public int foobar();
31+
}
32+
2333
/*
2434
/**********************************************************
2535
/* Unit tests
@@ -39,4 +49,23 @@ public void testIssue19() throws Exception
3949
final Map<String, Object> data = MAPPER.readValue(json, typeMap);
4050
assertEquals(Integer.valueOf(60), data.get("id"));
4151
}
52+
53+
// for [modules-base#42]: ignore `get()` and `set()`
54+
public void testPlainGetAndSet() throws Exception
55+
{
56+
JustGetAndSet value = MAPPER.readValue("{}", JustGetAndSet.class);
57+
// fine to have unimplemented methods, unless...
58+
assertNotNull(value);
59+
60+
AbstractTypeMaterializer mat = new AbstractTypeMaterializer();
61+
mat.enable(AbstractTypeMaterializer.Feature.FAIL_ON_UNMATERIALIZED_METHOD);
62+
ObjectMapper mapper = new ObjectMapper()
63+
.registerModule(new MrBeanModule(mat));
64+
try {
65+
mapper.readValue("{}", JustGetAndSet.class);
66+
fail("Should not pass");
67+
} catch (JsonMappingException e) {
68+
verifyException(e, "Unrecognized abstract method");
69+
}
70+
}
4271
}

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Modules:
1010

1111
2.9.0 (not yet released)
1212

13+
2.8.11.1 (not yet released)
14+
15+
#42: NPE from MrBean when `get()` or `set()` is though as property
16+
(reported by Tuomas K)
17+
1318
2.8.11 (24-Dec-2017)
1419

1520
#30: (afterburner) `IncompatibleClassChangeError` deserializing interface

0 commit comments

Comments
 (0)