From 9dd0cd9fb35ba82728346759c68974ea09df7d91 Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Thu, 24 Sep 2015 00:32:18 -0400 Subject: [PATCH] Provide a constructor that captures the JSON Rather than "debug" the JSON which does not allow further processing for the exception capture and put it inside the exception data. --- .../jayway/jsonpath/InvalidJsonException.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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; } }