protected Object wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt) throws IOException { throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, fieldName); }
/** * Method that can be called to either create a new JsonMappingException * (if underlying exception is not a JsonMappingException), or augment * given exception with given path/reference information. * * This version of method is called when the reference is through a * non-indexed object, such as a Map or POJO/bean. */ public static JsonMappingException wrapWithPath(Throwable src, Object refFrom, String refFieldName) { return wrapWithPath(src, new Reference(refFrom, refFieldName)); }
/** * Method that can be called to either create a new JsonMappingException * (if underlying exception is not a JsonMappingException), or augment * given exception with given path/reference information. * * This version of method is called when the reference is through an * index, which happens with arrays and Collections. */ public static JsonMappingException wrapWithPath(Throwable src, Object refFrom, int index) { return wrapWithPath(src, new Reference(refFrom, index)); }
/** * Method that will modify caught exception (passed in as argument) * as necessary to include reference information, and to ensure it * is a subtype of {@link IOException}, or an unchecked exception. *<p> * Rules for wrapping and unwrapping are bit complicated; essentially: *<ul> * <li>Errors are to be passed as is (if uncovered via unwrapping) * <li>"Plain" IOExceptions (ones that are not of type * {@link JsonMappingException} are to be passed as is *</ul> */ public void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt) throws IOException { // Need to add reference information throw JsonMappingException.wrapWithPath(throwOrReturnThrowable(t, ctxt), bean, fieldName); }
/** * Helper method called by various Map(-like) deserializers. */ protected <BOGUS> BOGUS wrapAndThrow(Throwable t, Object ref, String key) throws IOException { // to handle StackOverflow: while (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } // Errors and "plain" IOExceptions to be passed as is ClassUtil.throwIfError(t); // ... except for mapping exceptions if (t instanceof IOException && !(t instanceof JsonMappingException)) { throw (IOException) t; } // for [databind#1141] throw JsonMappingException.wrapWithPath(t, ref, ClassUtil.nonNull(key, "N/A")); } }
@SuppressWarnings("unchecked") protected final EnumSet<?> _deserialize(JsonParser p, DeserializationContext ctxt, EnumSet result) throws IOException { JsonToken t; try { while ((t = p.nextToken()) != JsonToken.END_ARRAY) { /* What to do with nulls? Fail or ignore? Fail, for now * (note: would fail if we passed it to EnumDeserializer, too, * but in general nulls should never be passed to non-container * deserializers) */ if (t == JsonToken.VALUE_NULL) { return (EnumSet<?>) ctxt.handleUnexpectedToken(_enumClass, p); } Enum<?> value = _enumDeserializer.deserialize(p, ctxt); /* 24-Mar-2012, tatu: As per [JACKSON-810], may actually get nulls; * but EnumSets don't allow nulls so need to skip. */ if (value != null) { result.add(value); } } } catch (Exception e) { throw JsonMappingException.wrapWithPath(e, result, result.size()); } return result; }
protected void wrapAndThrow(Throwable t, Object bean, String fieldName, DeserializationContext ctxt) throws IOException { // inlined 'throwOrReturnThrowable' while (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } // Errors to be passed as is ClassUtil.throwIfError(t); // StackOverflowErrors are tricky ones; need to be careful... boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS); // Ditto for IOExceptions; except we may want to wrap JSON exceptions if (t instanceof IOException) { if (!wrap || !(t instanceof JsonProcessingException)) { throw (IOException) t; } } else if (!wrap) { // allow disabling wrapping for unchecked exceptions ClassUtil.throwIfRTE(t); } throw JsonMappingException.wrapWithPath(t, bean, fieldName); }
public void wrapAndThrow(SerializerProvider provider, Throwable t, Object bean, int index) throws IOException { while (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } // Errors are to be passed as is ClassUtil.throwIfError(t); // Ditto for IOExceptions... except for mapping exceptions! boolean wrap = (provider == null) || provider.isEnabled(SerializationFeature.WRAP_EXCEPTIONS); if (t instanceof IOException) { if (!wrap || !(t instanceof JsonMappingException)) { throw (IOException) t; } } else if (!wrap) { ClassUtil.throwIfRTE(t); } // Need to add reference information throw JsonMappingException.wrapWithPath(t, bean, index); }
throw JsonMappingException.wrapWithPath(t, en, _accessor.getName() + "()");
throw JsonMappingException.wrapWithPath(t, bean, fieldName);
@SuppressWarnings("unchecked") protected EnumSet<?> handleNonArray(JsonParser p, DeserializationContext ctxt, EnumSet result) throws IOException { boolean canWrap = (_unwrapSingle == Boolean.TRUE) || ((_unwrapSingle == null) && ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); if (!canWrap) { return (EnumSet<?>) ctxt.handleUnexpectedToken(EnumSet.class, p); } // First: since `null`s not allowed, slightly simpler... if (p.hasToken(JsonToken.VALUE_NULL)) { return (EnumSet<?>) ctxt.handleUnexpectedToken(_enumClass, p); } try { Enum<?> value = _enumDeserializer.deserialize(p, ctxt); if (value != null) { result.add(value); } } catch (Exception e) { throw JsonMappingException.wrapWithPath(e, result, result.size()); } return result; } }
throw JsonMappingException.wrapWithPath(e, result, result.size());
throw JsonMappingException.wrapWithPath(e, Object.class, result.size());
throw JsonMappingException.wrapWithPath(e, chunk, builder.bufferedSize() + ix);
@Override public double[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { if (!p.isExpectedStartArrayToken()) { return handleNonArray(p, ctxt); } ArrayBuilders.DoubleBuilder builder = ctxt.getArrayBuilders().getDoubleBuilder(); double[] chunk = builder.resetAndStart(); int ix = 0; try { JsonToken t; while ((t = p.nextToken()) != JsonToken.END_ARRAY) { if (t == JsonToken.VALUE_NULL) { if (_nuller != null) { _nuller.getNullValue(ctxt); continue; } } double value = _parseDoublePrimitive(p, ctxt); if (ix >= chunk.length) { chunk = builder.appendCompletedChunk(chunk, ix); ix = 0; } chunk[ix++] = value; } } catch (Exception e) { throw JsonMappingException.wrapWithPath(e, chunk, builder.bufferedSize() + ix); } return builder.completeAndClearBuffer(chunk, ix); }
throw JsonMappingException.wrapWithPath(e, chunk, builder.bufferedSize() + ix);
throw JsonMappingException.wrapWithPath(e, chunk, builder.bufferedSize() + ix);
throw JsonMappingException.wrapWithPath(e, chunk, builder.bufferedSize() + ix);
ClassUtil.throwIfRTE(e); throw JsonMappingException.wrapWithPath(e, result, result.size());
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);