Skip to content

Commit

Permalink
Add a test for #2787, partial fix (no more NPE, now fails otherwise)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 8, 2020
1 parent a8dda6b commit eeac38b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,7 @@ Alexander Shilov (ashlanderr@github)
Endre Stølsvik (stolsvik@github)
* Reported #2679: `ObjectMapper.readValue("123", Void.TYPE)` throws "should never occur"
(2.10.4)

Denis Kostousov (kostousov-ds@github)
* Reported #2787 (partial fix): NPE after add mixin for enum
(2.10.5)
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.10.5 (not yet released)

#2787 (partial fix): NPE after add mixin for enum
(reported by Denis K)

2.10.4 (03-May-2020)

#2679: `ObjectMapper.readValue("123", Void.TYPE)` throws "should never occur"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private Map<String,FieldBuilder> _findFields(TypeResolutionContext tc,
fields.put(f.getName(), b);
}
// And then... any mix-in overrides?
if (_mixInResolver != null) {
if ((fields != null) && (_mixInResolver != null)) {
Class<?> mixin = _mixInResolver.findMixInClassFor(cls);
if (mixin != null) {
_addFieldMixIns(mixin, cls, fields);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.*;

public class EnumDeserialization2787Test extends BaseMapTest
{
// [databind#2787]
static enum SomeEnum2787 {
none,
tax10,
tax20
}

static enum SomeEnumMixin2787 {
@JsonProperty("zero")
none,
@JsonProperty("TypTyp")
tax10,
@JsonProperty("PytPyt")
tax20
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

protected final ObjectMapper MAPPER = newJsonMapper();

// [databind#2787]
public void testMixinOnEnumValues2787() throws Exception
{
ObjectMapper mapper = jsonMapperBuilder()
.addMixIn(SomeEnum2787.class, SomeEnumMixin2787.class)
.build();
SomeEnum2787 result = mapper.readValue(quote("zero"), SomeEnum2787.class);
assertEquals(SomeEnum2787.none, result);
}
}

0 comments on commit eeac38b

Please sign in to comment.