Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 11, 2019
1 parent 7904f92 commit e3ec9dc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
11 changes: 8 additions & 3 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,19 @@ Joe Barnett (josephlbarnett@github)
ignored when creator properties are buffered
(2.9.10)

Christoph Breitkopf (bokesan@github)
* Reported #2217: Suboptimal memory allocation in `TextNode.getBinaryValue()`
Yiqiu Huang (huangyq23@github
* Reported #2164: `FactoryBasedEnumDeserializer` does not respect
`DeserializationFeature.WRAP_EXCEPTIONS`
(2.10.0)

Alexander Saites (saites@github)
* Reported #2189: `TreeTraversingParser` does not check int bounds
(2.10.0)

Christoph Breitkopf (bokesan@github)
* Reported #2217: Suboptimal memory allocation in `TextNode.getBinaryValue()`
(2.10.0)

Pavel Chervakov (pacher@github)
* Reported #2230: `WRITE_BIGDECIMAL_AS_PLAIN` is ignored if `@JsonFormat` is used
(2.10.0)
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Project: jackson-databind

#2149: Add `MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES`
(suggested by Craig P)
#2164: `FactoryBasedEnumDeserializer` does not respect
`DeserializationFeature.WRAP_EXCEPTIONS`
(reported by Yiqiu H)
#2309: READ_ENUMS_USING_TO_STRING doesn't support null values
(reported, fix suggested by Ben A)
#2357: Lack of path on MismatchedInputException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ protected DeserializationContext(DeserializerFactory df) {
protected DeserializationContext(DeserializerFactory df,
DeserializerCache cache)
{
if (df == null) {
throw new IllegalArgumentException("Cannot pass null DeserializerFactory");
}
Objects.requireNonNull(df, "Cannot pass null DeserializerFactory");
_factory = df;
if (cache == null) {
cache = new DeserializerCache();
Expand Down Expand Up @@ -1090,6 +1088,10 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
}
// 18-May-2016, tatu: Only wrap if not already a valid type to throw
ClassUtil.throwIfIOE(t);
// [databind#2164]: but see if wrapping is desired
if (!isEnabled(DeserializationFeature.WRAP_EXCEPTIONS)) {
ClassUtil.throwIfRTE(t);
}
throw instantiationException(instClass, t);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

Expand Down Expand Up @@ -185,6 +186,16 @@ public static ObjectMapper setupObjectMapper(ObjectMapper mapper) {
}
}

// for [databind#2164]
public enum TestEnum2164 {
A, B;

@JsonCreator
public static TestEnum2164 fromString(String input) {
throw new IllegalArgumentException("2164");
}
}

// for [databind#2309]
static enum Enum2309 {
NON_NULL("NON_NULL"),
Expand Down Expand Up @@ -551,6 +562,31 @@ public void testExceptionFromCustomEnumKeyDeserializer() throws Exception {
}
}

// [databind#2164]
public void testWrapExceptions() throws Exception
{
// By default, wrap:
try {
MAPPER.readerFor(TestEnum2164.class)
.readValue(quote("B"));
fail("Should not pass");
} catch (ValueInstantiationException e) {
verifyException(e, "2164");
}

// But can disable:
try {
MAPPER.readerFor(TestEnum2164.class)
.without(DeserializationFeature.WRAP_EXCEPTIONS)
.readValue(quote("B"));
fail("Should not pass");
} catch (JsonMappingException e) {
fail("Wrong exception, should not wrap, got: "+e);
} catch (IllegalArgumentException e) {
verifyException(e, "2164");
}
}

// [databind#2309]
public void testEnumToStringNull2309() throws Exception
{
Expand All @@ -559,4 +595,5 @@ public void testEnumToStringNull2309() throws Exception
.readValue(quote("NON_NULL"));
assertEquals(Enum2309.NON_NULL, value);
}

}

0 comments on commit e3ec9dc

Please sign in to comment.