From 2c4e270a7b3287f23a43c61d6fb45afa9f05dc0d Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 24 Oct 2019 10:28:21 -0700 Subject: [PATCH] Fix #2520 --- release-notes/CREDITS-2.x | 5 +++++ release-notes/VERSION-2.x | 2 ++ .../jackson/databind/deser/BeanDeserializerBase.java | 2 +- .../databind/deser/creators/InnerClassCreatorTest.java | 8 ++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 0c1f4893ad..623d6c2dd5 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -990,3 +990,8 @@ Johan Haleby (johanhaleby@github) * Reported #2513: BigDecimalAsStringSerializer in NumberSerializer throws IllegalStateException in 2.10 (2.10.1) + +Mark Schäfer (mark--@github) + * Reported #2520: Sub-optimal exception message when failing to deserialize non-static inner classes + (2.10.1) + diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 7cf4890b3e..9c0fa029fb 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,8 @@ Project: jackson-databind (contributed by Marc M) #2513: BigDecimalAsStringSerializer in NumberSerializer throws IllegalStateException in 2.10 (reported by Johan H) +#2520: Sub-optimal exception message when failing to deserialize non-static inner classes + (reported by Mark S) 2.10.0 (26-Sep-2019) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java index 82cacd1fbe..4a15bfbcbe 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java @@ -1292,7 +1292,7 @@ protected Object deserializeFromObjectUsingNonDefault(JsonParser p, Class raw = _beanType.getRawClass(); if (ClassUtil.isNonStaticInnerClass(raw)) { return ctxt.handleMissingInstantiator(raw, null, p, -"can only instantiate non-static inner class by using default, no-argument constructor"); +"non-static inner classes like this can only by instantiated using default, no-argument constructor"); } return ctxt.handleMissingInstantiator(raw, getValueInstantiator(), p, "cannot deserialize from Object value (no delegate- or property-based Creator)"); diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/InnerClassCreatorTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/InnerClassCreatorTest.java index eeb733eb1e..044df22d00 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/InnerClassCreatorTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/InnerClassCreatorTest.java @@ -63,10 +63,10 @@ public void testIssue1501() throws Exception try { MAPPER.readValue(ser, Something1501.class); fail("Should not pass"); - } catch (JsonMappingException e) { + } catch (MismatchedInputException e) { verifyException(e, "Cannot construct instance"); verifyException(e, "InnerSomething1501"); - verifyException(e, "can only instantiate non-static inner class by using default"); + verifyException(e, "non-static inner classes like this can only by instantiated using default"); } } @@ -76,10 +76,10 @@ public void testIssue1502() throws Exception try { MAPPER.readValue(ser, Something1502.class); fail("Should not pass"); - } catch (JsonMappingException e) { + } catch (MismatchedInputException e) { verifyException(e, "Cannot construct instance"); verifyException(e, "InnerSomething1502"); - verifyException(e, "can only instantiate non-static inner class by using default"); + verifyException(e, "non-static inner classes like this can only by instantiated using default"); } }