@Override public String toString() { return getClass().getName()+": "+getMessage(); }
@Override public Application deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String name = null; List<InstanceInfo> instances = new ArrayList<>(); while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("name".equals(fieldName)) { name = jp.getValueAsString(); } else if ("instance".equals(fieldName)) { instances.add(jp.readValueAs(InstanceInfo.class)); } else { throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new Application(name, instances); } }
@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; } }
/** * @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; }
@Override public Iterable<T> apply(final InputStream input) { try (InputStream actual = input) { String text = CharStreams.toString(new InputStreamReader(actual)); return DEFAULT_MAPPER.readValue(text, type); } catch (UnrecognizedPropertyException e) { logger.info("Unrecognized field: {}", e.getMessage()); throw new MocoException(format("Unrecognized field [ %s ], please check!", e.getPropertyName())); } catch (JsonMappingException e) { logger.info("{} {}", e.getMessage(), e.getPathReference()); throw new MocoException(e); } catch (IOException e) { throw new MocoException(e); } } };
if (_filteredProps != null && provider.getActiveView() != null) { props = _filteredProps; } else { 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)); throw mapE;
expName = sstr.getValue(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw JsonMappingException.from(jp, "Current token not START_OBJECT (needed to unwrap root name '" +expName+"'), but "+jp.getCurrentToken()); if (jp.nextToken() != JsonToken.FIELD_NAME) { throw JsonMappingException.from(jp, "Current token not FIELD_NAME (to contain expected root name '" +expName+"'), but "+jp.getCurrentToken()); String actualName = jp.getCurrentName(); if (!expName.equals(actualName)) { throw JsonMappingException.from(jp, "Root name '"+actualName+"' does not match expected ('" +expName+"') for type "+rootType); jp.nextToken(); Object result = deser.deserialize(jp, ctxt); if (jp.nextToken() != JsonToken.END_OBJECT) { throw JsonMappingException.from(jp, "Current token not END_OBJECT (to match wrapper object with root name '" +expName+"'), but "+jp.getCurrentToken());
@Override public StackTraceElement deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); int lineNumber = -1; while ((t = jp.nextValue()) != JsonToken.END_OBJECT) { final String propName = jp.getCurrentName(); if ("class".equals(propName)) { className = jp.getText(); lineNumber = jp.getIntValue(); } else { throw JsonMappingException.from(jp, "Non-numeric token (" + t + ") for property 'lineNumber'"); throw ctxt.mappingException(_valueClass, t);
long previousLoginSuccessTime = -1; Map<String,List<String>> userAttributes = EMPTY_MAP; while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); if (NULL_STRING.equals(jp.getText())) { throw new JsonMappingException("Missing "+UaaPrincipal.class.getName());
throws IOException { if (!p.isExpectedStartArrayToken()) { return result; p.setCurrentValue(result); (valueDes.getObjectIdReader() == null) ? null : new CollectionReferringAccumulator(_containerType.getContentType().getRawClass(), result); while ((t = p.nextToken()) != JsonToken.END_ARRAY) { try { Object value; value = valueDes.deserialize(p, ctxt); } else { value = valueDes.deserializeWithType(p, ctxt, typeDeser); if (referringAccumulator == null) { throw JsonMappingException .from(p, "Unresolved forward reference but no identity info", reference); boolean wrap = (ctxt == null) || ctxt.isEnabled(DeserializationFeature.WRAP_EXCEPTIONS); if (!wrap) { ClassUtil.throwIfRTE(e); throw JsonMappingException.wrapWithPath(e, result, result.size());
JsonToken current = jp.getCurrentToken(); if (current == JsonToken.START_OBJECT) { current = jp.nextToken(); key = jp.getCurrentName(); } else { key = jp.nextFieldName(); final Object value = nestedObjectMapper.convertValue(children, new GenericTypeReference(field.getType())); if (value == null) { throw new JsonMappingException("Setting null to a task field is not allowed. Use Optional<T> to represent null."); throw new JsonMappingException(String.format( "FATAL: Expected to be a bug in Embulk. Mapping \"%s: (%s) %s\" might have already been processed, or not in %s.", key, Object value = nestedObjectMapper.readValue(field.getDefaultJsonString().get(), new GenericTypeReference(field.getType())); if (value == null) { throw new JsonMappingException("Setting null to a task field is not allowed. Use Optional<T> to represent null."); throw new JsonMappingException("Field '" + unused.getKey() + "' is required but not set", jp.getCurrentLocation());
while (p.nextToken() != JsonToken.END_OBJECT) { final Object key; if (keyDeserializer != null) { key = keyDeserializer.deserializeKey(p.getCurrentName(), ctxt); } else { key = p.getCurrentName(); value = elementDeserializer.deserializeWithType(p, ctxt, elementTypeDeserializer); } else { value = elementDeserializer.deserialize(p, ctxt); return map; } catch (InvocationTargetException e) { throw new JsonMappingException(p, "Could not map to " + type, _peel(e)); } catch (IllegalArgumentException e) { throw new JsonMappingException(p, "Could not map to " + type, _peel(e)); } catch (IllegalAccessException e) { throw new JsonMappingException(p, "Could not map to " + type, _peel(e));
@Override public SuperDuperNameList deserialize(JsonParser jp, DeserializationContext context) throws IOException { JsonToken token = jp.getCurrentToken(); if (token == JsonToken.VALUE_STRING) { return new SuperDuperNameList(jp.getText(), null); } context.handleUnexpectedToken(handledType(), jp); throw JsonMappingException.from(jp, null); } }
JsonToken t = p.getCurrentToken(); if (t == JsonToken.START_OBJECT) { t = p.nextToken(); BoundType upperBoundType = _defaultBoundType; for (; t != JsonToken.END_OBJECT; t = p.nextToken()) { expect(context, JsonToken.FIELD_NAME, t); String fieldName = p.getCurrentName(); context.handleUnknownProperty(p, this, Range.class, fieldName); throw JsonMappingException.from(p, e.getMessage()); throw JsonMappingException.from(p, e.getMessage());
@Override public final void deserializeAndSet(JsonParser jp, DeserializationContext ctxt, Object instance) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NULL) { /* Hmmh. Is this a problem? We won't be setting anything, so it's * equivalent of empty Collection/Map in this case */ return; } // Ok: then, need to fetch Collection/Map to modify: Object toModify; try { toModify = _getter.invoke(instance); } catch (Exception e) { _throwAsIOE(e); return; // never gets here } /* Note: null won't work, since we can't then inject anything * in. At least that's not good in common case. However, * theoretically the case where we get JSON null might * be compatible. If so, implementation could be changed. */ if (toModify == null) { throw new JsonMappingException("Problem deserializing 'setterless' property '"+getName()+"': get method returned null"); } _valueDeserializer.deserialize(jp, ctxt, toModify); }
private void expect(JsonParser p, JsonToken token) throws IOException { if (p.getCurrentToken() != token) { throw new JsonMappingException(p, "Expecting " + token + ", found " + p.getCurrentToken(), p.getCurrentLocation()); } }
@Override public final T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { try { ObjectCodec codec = jp.getCodec(); JsonNode tree = codec.readTree(jp); return deserializeObject(jp, ctxt, codec, tree); } catch (Exception ex) { if (ex instanceof IOException) { throw (IOException) ex; } throw new JsonMappingException(jp, "Object deserialize error", ex); } }
if (baseType.getContentType() == null) { // non-container/-structured types, usually scalar: if (baseType.hasRawClass(deserClass)) { // no change return baseType; if (!baseType.getRawClass().isAssignableFrom(deserClass)) { return baseType; return tf.constructSpecializedType(baseType, deserClass); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, String.format("Failed to narrow type %s with annotation (value %s), from '%s': %s", baseType, deserClass.getName(), a.getName(), iae.getMessage()), return baseType.withContentType(contentType); } catch (IllegalArgumentException iae) { throw new JsonMappingException(null, String.format("Failed to narrow type %s with annotation (value %s), from '%s': %s", baseType, deserClass.getName(), a.getName(), iae.getMessage()),
Object instance) throws IOException JsonToken t = p.getCurrentToken(); if (t == JsonToken.VALUE_NULL) { ctxt.reportMappingException( "Problem deserializing 'setterless' property (\"%s\"): no way to handle typed deser with setterless yet", getName()); throw JsonMappingException.from(p, "Problem deserializing 'setterless' property '"+getName()+"': get method returned null"); _valueDeserializer.deserialize(p, ctxt, toModify);
type = type.withStaticTyping(); } else { throw new JsonMappingException(null, String.format("Cannot refine serialization type %s into %s; types not related", type, serClass.getName())); throw new JsonMappingException(null, String.format("Failed to widen type %s with annotation (value %s), from '%s': %s", type, serClass.getName(), a.getName(), iae.getMessage()), keyType = keyType.withStaticTyping(); } else { throw new JsonMappingException(null, String.format("Cannot refine serialization key type %s into %s; types not related", keyType, keyClass.getName())); throw new JsonMappingException(null, String.format("Failed to widen key type of %s with concrete-type annotation (value %s), from '%s': %s", type, keyClass.getName(), a.getName(), iae.getMessage()), contentType = contentType.withStaticTyping(); } else { throw new JsonMappingException(null, String.format("Cannot refine serialization content type %s into %s; types not related", contentType, contentClass.getName())); throw new JsonMappingException(null, String.format("Internal error: failed to refine value type of %s with concrete-type annotation (value %s), from '%s': %s", type, contentClass.getName(), a.getName(), iae.getMessage()),