Skip to content

Commit eeac38b

Browse files
committed
Add a test for #2787, partial fix (no more NPE, now fails otherwise)
1 parent a8dda6b commit eeac38b

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

release-notes/CREDITS-2.x

+4
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,7 @@ Alexander Shilov (ashlanderr@github)
10481048
Endre Stølsvik (stolsvik@github)
10491049
* Reported #2679: `ObjectMapper.readValue("123", Void.TYPE)` throws "should never occur"
10501050
(2.10.4)
1051+
1052+
Denis Kostousov (kostousov-ds@github)
1053+
* Reported #2787 (partial fix): NPE after add mixin for enum
1054+
(2.10.5)

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.10.5 (not yet released)
8+
9+
#2787 (partial fix): NPE after add mixin for enum
10+
(reported by Denis K)
11+
712
2.10.4 (03-May-2020)
813

914
#2679: `ObjectMapper.readValue("123", Void.TYPE)` throws "should never occur"

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedFieldCollector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private Map<String,FieldBuilder> _findFields(TypeResolutionContext tc,
8181
fields.put(f.getName(), b);
8282
}
8383
// And then... any mix-in overrides?
84-
if (_mixInResolver != null) {
84+
if ((fields != null) && (_mixInResolver != null)) {
8585
Class<?> mixin = _mixInResolver.findMixInClassFor(cls);
8686
if (mixin != null) {
8787
_addFieldMixIns(mixin, cls, fields);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.annotation.*;
4+
5+
import com.fasterxml.jackson.databind.*;
6+
7+
public class EnumDeserialization2787Test extends BaseMapTest
8+
{
9+
// [databind#2787]
10+
static enum SomeEnum2787 {
11+
none,
12+
tax10,
13+
tax20
14+
}
15+
16+
static enum SomeEnumMixin2787 {
17+
@JsonProperty("zero")
18+
none,
19+
@JsonProperty("TypTyp")
20+
tax10,
21+
@JsonProperty("PytPyt")
22+
tax20
23+
}
24+
25+
/*
26+
/**********************************************************
27+
/* Test methods
28+
/**********************************************************
29+
*/
30+
31+
protected final ObjectMapper MAPPER = newJsonMapper();
32+
33+
// [databind#2787]
34+
public void testMixinOnEnumValues2787() throws Exception
35+
{
36+
ObjectMapper mapper = jsonMapperBuilder()
37+
.addMixIn(SomeEnum2787.class, SomeEnumMixin2787.class)
38+
.build();
39+
SomeEnum2787 result = mapper.readValue(quote("zero"), SomeEnum2787.class);
40+
assertEquals(SomeEnum2787.none, result);
41+
}
42+
}

0 commit comments

Comments
 (0)