Browse Source

All exceptions now inherit from JsonPathException

pull/57/head
Kalle Stenflo 10 years ago
parent
commit
109175f9f2
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/InvalidCriteriaException.java
  2. 2
      json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java
  3. 2
      json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java
  4. 33
      json-path/src/main/java/com/jayway/jsonpath/JsonPathException.java
  5. 2
      json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java
  6. 8
      json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java
  7. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java
  8. 5
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/GsonJsonProvider.java
  9. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JsonSmartJsonProvider.java
  10. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/mapper/GsonMappingProvider.java
  11. 4
      json-path/src/main/java/com/jayway/jsonpath/spi/mapper/MappingException.java

2
json-path/src/main/java/com/jayway/jsonpath/InvalidCriteriaException.java

@ -15,7 +15,7 @@
package com.jayway.jsonpath;
@SuppressWarnings("serial")
public class InvalidCriteriaException extends RuntimeException {
public class InvalidCriteriaException extends JsonPathException {
public InvalidCriteriaException() {
}

2
json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java

@ -15,7 +15,7 @@
package com.jayway.jsonpath;
@SuppressWarnings("serial")
public class InvalidJsonException extends RuntimeException {
public class InvalidJsonException extends JsonPathException {
public InvalidJsonException() {
}

2
json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java

@ -15,7 +15,7 @@
package com.jayway.jsonpath;
@SuppressWarnings("serial")
public class InvalidPathException extends RuntimeException {
public class InvalidPathException extends JsonPathException {
public InvalidPathException() {
}

33
json-path/src/main/java/com/jayway/jsonpath/JsonPathException.java

@ -0,0 +1,33 @@
/*
* Copyright 2011 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jayway.jsonpath;
public class JsonPathException extends RuntimeException {
public JsonPathException() {
}
public JsonPathException(String message) {
super(message);
}
public JsonPathException(String message, Throwable cause) {
super(message, cause);
}
public JsonPathException(Throwable cause) {
super(cause);
}
}

2
json-path/src/main/java/com/jayway/jsonpath/ValueCompareException.java

@ -14,5 +14,5 @@
*/
package com.jayway.jsonpath;
public class ValueCompareException extends RuntimeException {
public class ValueCompareException extends JsonPathException {
}

8
json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java

@ -14,6 +14,8 @@
*/
package com.jayway.jsonpath.internal;
import com.jayway.jsonpath.JsonPathException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
@ -306,7 +308,7 @@ public final class Utils {
out.writeObject(obj);
} catch (IOException ex) {
throw new RuntimeException(ex);
throw new JsonPathException(ex);
} finally {
try {
if (out != null) {
@ -361,9 +363,9 @@ public final class Utils {
return in.readObject();
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
throw new JsonPathException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
throw new JsonPathException(ex);
} finally {
try {
if (in != null) {

3
json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java

@ -14,6 +14,7 @@
*/
package com.jayway.jsonpath.internal.spi.json;
import com.jayway.jsonpath.JsonPathException;
import com.jayway.jsonpath.spi.json.JsonProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -127,7 +128,7 @@ public abstract class AbstractJsonProvider implements JsonProvider {
} else if(obj instanceof String){
return ((String)obj).length();
}
throw new RuntimeException("length operation can not applied to " + obj!=null?obj.getClass().getName():"null");
throw new JsonPathException("length operation can not applied to " + obj!=null?obj.getClass().getName():"null");
}
/**

5
json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/GsonJsonProvider.java

@ -23,6 +23,7 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.internal.LazilyParsedNumber;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPathException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -102,7 +103,7 @@ public class GsonJsonProvider extends AbstractJsonProvider {
try {
return parser.parse(new InputStreamReader(jsonStream, charset));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
throw new JsonPathException(e);
}
}
@ -187,7 +188,7 @@ public class GsonJsonProvider extends AbstractJsonProvider {
}
}
}
throw new RuntimeException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null");
throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null");
}
@Override

3
json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JsonSmartJsonProvider.java

@ -15,6 +15,7 @@
package com.jayway.jsonpath.internal.spi.json;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.JsonPathException;
import com.jayway.jsonpath.spi.json.Mode;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@ -62,7 +63,7 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
} catch (ParseException e) {
throw new InvalidJsonException(e);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
throw new JsonPathException(e);
}
}

3
json-path/src/main/java/com/jayway/jsonpath/internal/spi/mapper/GsonMappingProvider.java

@ -14,6 +14,7 @@
*/
package com.jayway.jsonpath.internal.spi.mapper;
import com.jayway.jsonpath.JsonPathException;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,7 +30,7 @@ public class GsonMappingProvider extends DefaultMappingProvider implements Mappi
addMapper(new GsonMapper());
} catch (ClassNotFoundException e) {
logger.error("Gson not found on class path. No converters configured.");
throw new RuntimeException("Gson not found on path", e);
throw new JsonPathException("Gson not found on path", e);
}
}
}

4
json-path/src/main/java/com/jayway/jsonpath/spi/mapper/MappingException.java

@ -14,7 +14,9 @@
*/
package com.jayway.jsonpath.spi.mapper;
public class MappingException extends RuntimeException {
import com.jayway.jsonpath.JsonPathException;
public class MappingException extends JsonPathException {
public MappingException(Throwable cause) {
super(cause);

Loading…
Cancel
Save