@Override public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { if (value != null) { throw JsonMappingException.from(gen, "Jsr310NullKeySerializer is only for serializing null values."); } gen.writeFieldName(NULL_KEY); }
/** * @deprecated Since 2.8 use {@link #handleUnexpectedToken(Class, JsonParser)} instead */ @Deprecated public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) { return JsonMappingException.from(_parser, String.format("Cannot deserialize instance of %s out of %s token", ClassUtil.nameOf(targetClass), token)); }
/** * @since 2.9 */ public static <T> T throwAsMappingException(DeserializationContext ctxt, IOException e0) throws JsonMappingException { if (e0 instanceof JsonMappingException) { throw (JsonMappingException) e0; } JsonMappingException e = JsonMappingException.from(ctxt, e0.getMessage()); e.initCause(e0); throw e; }
/** * Helper method for constructing generic mapping exception with specified * message and current location information. * Note that application code should almost always call * one of <code>handleXxx</code> methods, or {@link #reportMappingException(String, Object...)} * instead. * * @since 2.6 * * @deprecated Since 2.9 use more specific error reporting methods instead */ @Deprecated public JsonMappingException mappingException(String message) { return JsonMappingException.from(getParser(), message); }
/** * Factory method for constructing a {@link JsonMappingException}; * usually only indirectly used by calling * {@link #reportMappingProblem(Throwable, String, Object...)} * * @since 2.8 * * @deprecated Since 2.9 */ @Deprecated // since 2.9 protected JsonMappingException mappingException(Throwable t, String message, Object... msgArgs) { return JsonMappingException.from(getGenerator(), _format(message, msgArgs), t); }
/** * Factory method for constructing a {@link JsonMappingException}; * usually only indirectly used by calling * {@link #reportMappingProblem(String, Object...)}. * * @since 2.6 * * @deprecated Since 2.9 */ @Deprecated // since 2.9 public JsonMappingException mappingException(String message, Object... msgArgs) { return JsonMappingException.from(getGenerator(), _format(message, msgArgs)); }
/** * Helper method for constructing generic mapping exception with specified * message and current location information * Note that application code should almost always call * one of <code>handleXxx</code> methods, or {@link #reportMappingException(String, Object...)} * instead. * * @since 2.6 * * @deprecated Since 2.9 use more specific error reporting methods instead */ @Deprecated public JsonMappingException mappingException(String msg, Object... msgArgs) { return JsonMappingException.from(getParser(), _format(msg, msgArgs)); }
/** * Helper method called to indicate problem; default behavior is to construct and * throw a {@link JsonMappingException}, but in future may collect more than one * and only throw after certain number, or at the end of serialization. * * @since 2.8 */ public void reportMappingProblem(Throwable t, String message, Object... msgArgs) throws JsonMappingException { message = _format(message, msgArgs); throw JsonMappingException.from(getGenerator(), message, t); }
/** * Fallback method that may be called if no other <code>reportXxx</code> * is applicable -- but only in that case. * * @since 2.8 * * @deprecated Since 2.9: use a more specific method, or {@link #reportBadDefinition(JavaType, String)}, * or {@link #reportInputMismatch} instead */ @Deprecated // since 2.9 public void reportMappingException(String msg, Object... msgArgs) throws JsonMappingException { throw JsonMappingException.from(getParser(), _format(msg, msgArgs)); }
/** * 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); }
/** * @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); }
throw JsonMappingException.from(ctxt, ClassUtil.exceptionMessage(iae), iae);
public Object handleWeirdNativeValue(JavaType targetType, Object badValue, JsonParser p) throws IOException { LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers(); final Class<?> raw = targetType.getRawClass(); for (; h != null; h = h.next()) { // Can bail out if it's handled Object goodValue = h.value().handleWeirdNativeValue(this, targetType, badValue, p); if (goodValue != DeserializationProblemHandler.NOT_HANDLED) { // Sanity check for broken handlers, otherwise nasty to debug: if ((goodValue == null) || raw.isInstance(goodValue)) { return goodValue; } throw JsonMappingException.from(p, _format( "DeserializationProblemHandler.handleWeirdNativeValue() for type %s returned value of type %s", targetType, goodValue.getClass())); } } throw weirdNativeValueException(badValue, raw); }
@Override public Object deserializeSetAndReturn(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException { try { return setAndReturn(instance, deserialize(p, ctxt)); } catch (UnresolvedForwardReference reference) { boolean usingIdentityInfo = (_objectIdInfo != null) || (_valueDeserializer.getObjectIdReader() != null); if (!usingIdentityInfo) { throw JsonMappingException.from(p, "Unresolved forward reference but no identity info", reference); } reference.getRoid().appendReferring(new PropertyReferring(this, reference, _type.getRawClass(), instance)); return null; } }
wrapAndThrow(provider, e, bean, name); } catch (StackOverflowError e) { JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e); String name = (i == props.length) ? "[anySetter]" : props[i].getName(); mapE.prependPath(new JsonMappingException.Reference(bean, name));
lineNumber = jp.getIntValue(); } else { throw JsonMappingException.from(jp, "Non-numeric token (" + t + ") for property 'lineNumber'");
/** * Method called to deserialize appropriate value, given parser (and * context), and set it using appropriate method (a setter method). */ public final void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object instance, String propName) throws IOException { try { Object key = (_keyDeserializer == null) ? propName : _keyDeserializer.deserializeKey(propName, ctxt); set(instance, key, deserialize(p, ctxt)); } catch (UnresolvedForwardReference reference) { if (!(_valueDeserializer.getObjectIdReader() != null)) { throw JsonMappingException.from(p, "Unresolved forward reference but no identity info.", reference); } AnySetterReferring referring = new AnySetterReferring(this, reference, _type.getRawClass(), instance, propName); reference.getRoid().appendReferring(referring); } }
if (referringAccumulator == null) { throw JsonMappingException .from(p, "Unresolved forward reference but no identity info", reference);
String name = jsonNode.get("name") != null ? jsonNode.get("name").asText() : null; if (name == null) { throw JsonMappingException.from(p, "No name for DOM element was provided in the JSON object.");