From 2b0485bb39c5f79ee15fb280cd73c67205b6e5e5 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 13 Jun 2020 11:25:10 -0700 Subject: [PATCH] more refactoring --- .../databind/deser/std/StdDeserializer.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java index e95b83f1f9..9dc7f73112 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java @@ -1278,6 +1278,43 @@ protected final void _verifyNullForPrimitiveCoercion(DeserializationContext ctxt _reportFailedNullCoerce(ctxt, enable, feat, strDesc); } + protected void _reportFailedNullCoerce(DeserializationContext ctxt, boolean state, Enum feature, + String inputDesc) throws JsonMappingException + { + String enableDesc = state ? "enable" : "disable"; + ctxt.reportInputMismatch(this, "Cannot coerce %s to Null value as %s (%s `%s.%s` to allow)", + inputDesc, _coercedTypeDesc(), enableDesc, feature.getClass().getSimpleName(), feature.name()); + } + + /** + * Helper method called to get a description of type into which a scalar value coercion + * is (most likely) being applied, to be used for constructing exception messages + * on coerce failure. + * + * @return Message with backtick-enclosed name of type this deserializer supports + * + * @since 2.9 + */ + protected String _coercedTypeDesc() { + boolean structured; + String typeDesc; + + JavaType t = getValueType(); + if ((t != null) && !t.isPrimitive()) { + structured = (t.isContainerType() || t.isReferenceType()); + typeDesc = ClassUtil.getTypeDescription(t); + } else { + Class cls = handledType(); + structured = cls.isArray() || Collection.class.isAssignableFrom(cls) + || Map.class.isAssignableFrom(cls); + typeDesc = ClassUtil.getClassDescription(cls); + } + if (structured) { + return "element of "+typeDesc; + } + return typeDesc+" value"; + } + /* /********************************************************************** /* Helper methods for sub-classes, coercions, older (pre-2.12), deprecated @@ -1352,43 +1389,6 @@ protected void _verifyNumberForScalarCoercion(DeserializationContext ctxt, JsonP } } - protected void _reportFailedNullCoerce(DeserializationContext ctxt, boolean state, Enum feature, - String inputDesc) throws JsonMappingException - { - String enableDesc = state ? "enable" : "disable"; - ctxt.reportInputMismatch(this, "Cannot coerce %s to Null value as %s (%s `%s.%s` to allow)", - inputDesc, _coercedTypeDesc(), enableDesc, feature.getClass().getSimpleName(), feature.name()); - } - - /** - * Helper method called to get a description of type into which a scalar value coercion - * is (most likely) being applied, to be used for constructing exception messages - * on coerce failure. - * - * @return Message with backtick-enclosed name of type this deserializer supports - * - * @since 2.9 - */ - protected String _coercedTypeDesc() { - boolean structured; - String typeDesc; - - JavaType t = getValueType(); - if ((t != null) && !t.isPrimitive()) { - structured = (t.isContainerType() || t.isReferenceType()); - typeDesc = ClassUtil.getTypeDescription(t); - } else { - Class cls = handledType(); - structured = cls.isArray() || Collection.class.isAssignableFrom(cls) - || Map.class.isAssignableFrom(cls); - typeDesc = ClassUtil.getClassDescription(cls); - } - if (structured) { - return "element of "+typeDesc; - } - return typeDesc+" value"; - } - /* /**************************************************** /* Helper methods for sub-classes, resolving dependencies