diff --git a/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java b/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java index 5c660b38..cfad167b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java +++ b/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java @@ -17,18 +17,42 @@ package com.jayway.jsonpath; @SuppressWarnings("serial") public class InvalidJsonException extends JsonPathException { + /** + * Problematic JSON if available. + */ + private final String json; + public InvalidJsonException() { + json = null; } public InvalidJsonException(String message) { super(message); + json = null; } public InvalidJsonException(String message, Throwable cause) { super(message, cause); + json = null; } public InvalidJsonException(Throwable cause) { super(cause); + json = null; + } + + /** + * Rethrow the exception with the problematic JSON captured. + */ + public InvalidJsonException(final Throwable cause, final String json) { + super(cause); + this.json = json; + } + + /** + * @return the problematic JSON if available. + */ + public String getJson() { + return json; } }