From 286aff4818810b32a7884fe2cdba8a558b770d0d Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Thu, 1 Oct 2015 18:31:04 -0400 Subject: [PATCH] Alternate constructor for ValueCompareException This passes the message in the exception rather than being lost in the logs. --- .../src/main/java/com/jayway/jsonpath/Criteria.java | 3 +-- .../com/jayway/jsonpath/ValueCompareException.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java index 28c75744..3df64a34 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/Criteria.java +++ b/json-path/src/main/java/com/jayway/jsonpath/Criteria.java @@ -912,8 +912,7 @@ public class Criteria implements Predicate { JsonValue json = (JsonValue) left; return right.equals(json.parsed(ctx)) ? 0 : -1; } else { - logger.debug("Can not compare a {} with a {}", left.getClass().getName(), right.getClass().getName()); - throw new ValueCompareException(); + throw new ValueCompareException(left, right); } } diff --git a/json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java b/json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java index b9cffccb..94d84094 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java +++ b/json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java @@ -19,6 +19,16 @@ public class ValueCompareException extends JsonPathException { public ValueCompareException() { } + /** + * Construct the exception with message capturing the classes for two objects. + * + * @param left first object + * @param right second object + */ + public ValueCompareException(final Object left, final Object right) { + super(String.format("Can not compare a %1s with a %2s", left.getClass().getName(), right.getClass().getName())); + } + public ValueCompareException(String message) { super(message); }