/** * @since 2.7 */ public static JsonMappingException from(JsonParser p, String msg, Throwable problem) { return new JsonMappingException(p, msg, problem); }
/** * @since 2.7 */ public static JsonMappingException from(JsonParser p, String msg) { return new JsonMappingException(p, msg); }
/** * @since 2.7 */ public static JsonMappingException from(JsonGenerator g, String msg) { return new JsonMappingException(g, msg, (Throwable) null); }
/** * @since 2.7 */ public static JsonMappingException from(JsonGenerator g, String msg, Throwable problem) { return new JsonMappingException(g, msg, problem); }
/** * @since 2.7 */ public static JsonMappingException from(SerializerProvider ctxt, String msg) { return new JsonMappingException(ctxt.getGenerator(), msg); }
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); }
/** * @since 2.7 */ public static JsonMappingException from(DeserializationContext ctxt, String msg, Throwable t) { return new JsonMappingException(ctxt.getParser(), msg, t); }
/** * @since 2.7 */ public static JsonMappingException from(SerializerProvider ctxt, String msg, Throwable problem) { /* 17-Aug-2015, tatu: As per [databind#903] this is bit problematic as * SerializerProvider instance does not currently hold on to generator... */ return new JsonMappingException(ctxt.getGenerator(), msg, problem); }
/** * @since 2.7 */ public static JsonMappingException from(DeserializationContext ctxt, String msg) { return new JsonMappingException(ctxt.getParser(), msg); }
@Override protected Charset _deserialize(String value, DeserializationContext context) throws JsonMappingException { try { return Charset.forName(value); } catch (UnsupportedOperationException ex) { // TODO include link to a document to the message for the list of supported time zones throw new JsonMappingException(String.format("Unknown charset '%s'", value)); } } }
@Override protected Type _deserialize(String value, DeserializationContext context) throws IOException { Type t = stringToTypeMap.get(value); if (t == null) { throw new JsonMappingException( String.format("Unknown type name '%s'. Supported types are: %s", value, Joiner.on(", ").join(stringToTypeMap.keySet()))); } return t; } }
/** * 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 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 protected org.joda.time.DateTimeZone _deserialize(String value, DeserializationContext context) throws JsonMappingException { org.joda.time.DateTimeZone parsed = TimeZoneIds.parseJodaDateTimeZone(value); if (parsed == null) { // TODO include link to a document to the message for the list of supported time zones throw new JsonMappingException(String.format("Unknown time zone name '%s'", value)); } return parsed; } }
@Override public InstanceInfo.PortWrapper deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { boolean enabled = false; int port = 0; while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("enabled".equals(fieldName)) { enabled = Boolean.valueOf(jp.getValueAsString()); } else if (fieldName == null || "".equals(fieldName)) { String value = jp.getValueAsString(); port = value == null ? 0 : Integer.parseInt(value); } else { throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new InstanceInfo.PortWrapper(enabled, port); } }
/** * @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); }
@Deprecated public ToString(com.google.common.base.Optional<JsonNode> option) throws JsonMappingException { JsonNode node = option.or(NullNode.getInstance()); if (node.isTextual()) { this.string = node.textValue(); } else if (node.isValueNode()) { this.string = node.toString(); } else { throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node)); } }
@JsonCreator public ToString(final Optional<JsonNode> option) throws JsonMappingException { final JsonNode node = option.orElse(NullNode.getInstance()); if (node.isTextual()) { this.string = node.textValue(); } else if (node.isValueNode()) { this.string = node.toString(); } else { throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node)); } }
@Override @SuppressWarnings("unchecked") public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode json = treeObjectMapper.readTree(jp); if (!json.isObject()) { throw new JsonMappingException("Expected object to deserialize DataSource", jp.getCurrentLocation()); } return (T) new DataSourceImpl(model, (ObjectNode) json); } }
/** * @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); }