Skip to content

Commit d2beeb7

Browse files
committed
backport #324 fix for 2.2.4
1 parent 803536b commit d2beeb7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

release-notes/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Project: jackson-databind
22
Version: 2.2.4 (xx-xxx-2013)
33

44
#292: Problems with abstract `Map`s, `Collection`s, polymorphic deserialization
5+
#324: EnumDeserializer should throw JsonMappingException, not IllegalArgumentException
56

67
------------------------------------------------------------------------
78
=== History: ===

src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ public Object deserialize(JsonParser jp, DeserializationContext ctxt)
161161
try {
162162
return _factory.invoke(_enumClass, value);
163163
} catch (Exception e) {
164-
ClassUtil.unwrapAndThrowAsIAE(e);
164+
Throwable t = ClassUtil.getRootCause(e);
165+
if (t instanceof IOException) {
166+
throw (IOException) t;
167+
}
168+
throw ctxt.instantiationException(_enumClass, t);
165169
}
166-
return null;
167170
}
168171
}
169172
}

src/test/java/com/fasterxml/jackson/databind/deser/TestEnumDeserialization.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ private TestEnumFor834(int id) {
9797
}
9898
}
9999

100+
// [Issue#324]: exception from creator method
101+
protected enum TestEnum324
102+
{
103+
A, B;
104+
105+
@JsonCreator public static TestEnum324 creator(String arg) {
106+
throw new RuntimeException("Foobar!");
107+
}
108+
}
109+
100110
/*
101111
/**********************************************************
102112
/* Tests
@@ -318,8 +328,7 @@ public void testDoNotAllowUnknownEnumValuesAsMapKeysWhenReadAsNullDisabled() thr
318328
// [JACKSON-834]
319329
public void testEnumsFromInts() throws Exception
320330
{
321-
ObjectMapper mapper = new ObjectMapper();
322-
TestEnumFor834 res = mapper.readValue("1 ", TestEnumFor834.class);
331+
TestEnumFor834 res = MAPPER.readValue("1 ", TestEnumFor834.class);
323332
assertSame(TestEnumFor834.ENUM_A, res);
324333
}
325334

0 commit comments

Comments
 (0)