private IOException _wrapAsIOE(JsonGenerator g, Exception e) { if (e instanceof IOException) { return (IOException) e; } String msg = ClassUtil.exceptionMessage(e); if (msg == null) { msg = "[no message for "+e.getClass().getName()+"]"; } return new JsonMappingException(g, msg, e); }
protected Object _weirdKey(DeserializationContext ctxt, String key, Exception e) throws IOException { return ctxt.handleWeirdKey(_keyClass, key, "problem: %s", ClassUtil.exceptionMessage(e)); }
/** * Factory method used when "upgrading" an {@link IOException} into * {@link JsonMappingException}: usually only needed to comply with * a signature. *<p> * NOTE: since 2.9 should usually NOT be used on input-side (deserialization) * exceptions; instead use method(s) of <code>InputMismatchException</code> * * @since 2.1 */ public static JsonMappingException fromUnexpectedIOE(IOException src) { return new JsonMappingException(null, String.format("Unexpected IOException (of type %s): %s", src.getClass().getName(), ClassUtil.exceptionMessage(src))); }
@Override public boolean includeFilterSuppressNulls(Object filter) throws JsonMappingException { if (filter == null) { return true; } // should let filter decide what to do with nulls: // But just case, let's handle unexpected (from our perspective) problems explicitly try { return filter.equals(null); } catch (Throwable t) { String msg = String.format( "Problem determining whether filter of type '%s' should filter out `null` values: (%s) %s", filter.getClass().getName(), t.getClass().getName(), ClassUtil.exceptionMessage(t)); reportBadDefinition(filter.getClass(), msg, t); return false; // never gets here } }
/** * Convenience method for parsing a Date from given String, using * currently configured date format (accessed using * {@link DeserializationConfig#getDateFormat()}). *<p> * Implementation will handle thread-safety issues related to * date formats such that first time this method is called, * date format is cloned, and cloned instance will be retained * for use during this deserialization round. */ public Date parseDate(String dateStr) throws IllegalArgumentException { try { DateFormat df = getDateFormat(); return df.parse(dateStr); } catch (ParseException e) { throw new IllegalArgumentException(String.format( "Failed to parse Date value '%s': %s", dateStr, ClassUtil.exceptionMessage(e))); } }
/** * @deprecated Since 2.7 call either {@link #unwrapAndWrapException} or * {@link #wrapAsJsonMappingException} */ @Deprecated // since 2.7 protected JsonMappingException wrapException(Throwable t) { // 05-Nov-2015, tatu: This used to always unwrap the whole exception, but now only // does so if and until `JsonMappingException` is found. for (Throwable curr = t; curr != null; curr = curr.getCause()) { if (curr instanceof JsonMappingException) { return (JsonMappingException) curr; } } return new JsonMappingException(null, "Instantiation of "+getValueTypeDesc()+" value failed: "+ClassUtil.exceptionMessage(t), t); }
/** * Method that takes in exception of any type, and casts or wraps it * to an IOException or its subclass. */ protected void _throwAsIOE(JsonParser p, Exception e, Object value) throws IOException { if (e instanceof IllegalArgumentException) { String actType = ClassUtil.classNameOf(value); StringBuilder msg = new StringBuilder("Problem deserializing property '") .append(getName()) .append("' (expected type: ") .append(getType()) .append("; actual type: ") .append(actType).append(")"); String origMsg = ClassUtil.exceptionMessage(e); if (origMsg != null) { msg.append(", problem: ") .append(origMsg); } else { msg.append(" (no error message provided)"); } throw JsonMappingException.from(p, msg.toString(), e); } _throwAsIOE(p, e); }
/** * @param e Exception to re-throw or wrap * @param propName Name of property (from Json input) to set * @param value Value of the property */ protected void _throwAsIOE(Exception e, Object propName, Object value) throws IOException { if (e instanceof IllegalArgumentException) { String actType = ClassUtil.classNameOf(value); StringBuilder msg = new StringBuilder("Problem deserializing \"any\" property '").append(propName); msg.append("' of class "+getClassName()+" (expected type: ").append(_type); msg.append("; actual type: ").append(actType).append(")"); String origMsg = ClassUtil.exceptionMessage(e); if (origMsg != null) { msg.append(", problem: ").append(origMsg); } else { msg.append(" (no error message provided)"); } throw new JsonMappingException(null, msg.toString(), e); } ClassUtil.throwIfIOE(e); ClassUtil.throwIfRTE(e); // let's wrap the innermost problem Throwable t = ClassUtil.getRootCause(e); throw new JsonMappingException(null, ClassUtil.exceptionMessage(t), t); }
} else { String msg = ClassUtil.exceptionMessage(src);
@Override public Object instantiateBean(boolean fixAccess) { AnnotatedConstructor ac = _classInfo.getDefaultConstructor(); if (ac == null) { return null; } if (fixAccess) { ac.fixAccess(_config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS)); } try { return ac.getAnnotated().newInstance(); } catch (Exception e) { Throwable t = e; while (t.getCause() != null) { t = t.getCause(); } ClassUtil.throwIfError(t); ClassUtil.throwIfRTE(t); throw new IllegalArgumentException("Failed to instantiate bean of type " +_classInfo.getAnnotated().getName()+": ("+t.getClass().getName()+") " +ClassUtil.exceptionMessage(t), t); } }
@Override public Object deserializeKey(String key, DeserializationContext ctxt) throws IOException { if (key == null) { // is this even legal call? return null; } try { Object result = _parse(key, ctxt); if (result != null) { return result; } } catch (Exception re) { return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s", re.getClass().getName(), ClassUtil.exceptionMessage(re)); } if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) { return null; } return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation"); }
protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type) throws JsonMappingException { JsonSerializer<Object> ser; try { ser = _createUntypedSerializer(type); } catch (IllegalArgumentException iae) { // We better only expose checked exceptions, since those // are what caller is expected to handle ser = null; reportMappingProblem(iae, ClassUtil.exceptionMessage(iae)); } if (ser != null) { // 21-Dec-2015, tatu: Should we also cache using raw key? _serializerCache.addAndResolveNonTypedSerializer(type, ser, this); } return ser; }
/** * @since 2.7 */ protected IOException _throwAsIOE(JsonParser p, Exception e) throws IOException { ClassUtil.throwIfIOE(e); ClassUtil.throwIfRTE(e); // let's wrap the innermost problem Throwable th = ClassUtil.getRootCause(e); throw JsonMappingException.from(p, ClassUtil.exceptionMessage(th), th); }
/** * Helper method for constructing instantiation exception for specified type, * to indicate problem with physically constructing instance of * specified class (missing constructor, exception from constructor) *<p> * Note that most of the time this method should NOT be called directly; instead, * {@link #handleInstantiationProblem} should be called which will call this method * if necessary. */ public JsonMappingException instantiationException(Class<?> instClass, Throwable cause) { // Most likely problem with Creator definition, right? final JavaType type = constructType(instClass); String excMsg; if (cause == null) { excMsg = "N/A"; } else if ((excMsg = ClassUtil.exceptionMessage(cause)) == null) { excMsg = ClassUtil.nameOf(cause.getClass()); } String msg = String.format("Cannot construct instance of %s, problem: %s", ClassUtil.nameOf(instClass), excMsg); InvalidDefinitionException e = InvalidDefinitionException.from(_parser, msg, type); e.initCause(cause); return e; }
/** * @since 2.8 */ protected java.util.Date _parseDate(String value, DeserializationContext ctxt) throws IOException { try { // Take empty Strings to mean 'empty' Value, usually 'null': if (_isEmptyOrTextualNull(value)) { return (java.util.Date) getNullValue(ctxt); } return ctxt.parseDate(value); } catch (IllegalArgumentException iae) { return (java.util.Date) ctxt.handleWeirdStringValue(_valueClass, value, "not a valid representation (error: %s)", ClassUtil.exceptionMessage(iae)); } }
throw JsonMappingException.from(ctxt, ClassUtil.exceptionMessage(iae), iae);
/** * Method that will try to construct a value serializer; and if * one is successfully created, cache it for reuse. */ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawType) throws JsonMappingException { JavaType fullType = _config.constructType(rawType); JsonSerializer<Object> ser; try { ser = _createUntypedSerializer(fullType); } catch (IllegalArgumentException iae) { // We better only expose checked exceptions, since those // are what caller is expected to handle ser = null; // doesn't matter but compiler whines otherwise reportMappingProblem(iae, ClassUtil.exceptionMessage(iae)); } if (ser != null) { // 21-Dec-2015, tatu: Best to cache for both raw and full-type key _serializerCache.addAndResolveNonTypedSerializer(rawType, fullType, ser, this); } return ser; }
"problem: (%s) %s", e.getClass().getName(), ClassUtil.exceptionMessage(e)));
} catch (IllegalArgumentException e0) { InvalidDefinitionException e = InvalidDefinitionException.from((JsonParser) null, ClassUtil.exceptionMessage(e0), baseType); e.initCause(e0); throw e;
ClassUtil.exceptionMessage(e), builderDesc, null);