Browse Source

Removed createNull from JsonProvider

pull/56/head
Kalle Stenflo 10 years ago
parent
commit
4ad4647754
  1. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java
  2. 6
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/GsonJsonProvider.java
  3. 5
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java
  4. 24
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

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

@ -26,10 +26,6 @@ public abstract class AbstractJsonProvider implements JsonProvider {
private static final Logger logger = LoggerFactory.getLogger(AbstractJsonProvider.class);
@Override
public Object createNull(){
return null;
}
/**
* checks if object is an array

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

@ -98,12 +98,6 @@ public class GsonJsonProvider extends AbstractJsonProvider {
return obj.toString();
}
@Override
public Object createNull() {
return JsonNull.INSTANCE;
}
@Override
public Object createArray() {
return new JsonArray();

5
json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

@ -27,7 +27,7 @@ public abstract class PathToken {
if(propertyVal == JsonProvider.UNDEFINED){
if(isLeaf()) {
if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)){
propertyVal = ctx.jsonProvider().createNull();
propertyVal = null;
} else {
if(ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){
return;
@ -38,7 +38,6 @@ public abstract class PathToken {
}
} else {
throw new PathNotFoundException();
//return;
}
}
if (isLeaf()) {
@ -58,7 +57,7 @@ public abstract class PathToken {
Object propertyVal = readObjectProperty(property, model, ctx);
if(propertyVal == JsonProvider.UNDEFINED){
if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)){
propertyVal = ctx.jsonProvider().createNull();;
propertyVal = null;
} else {
continue;
}

24
json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

@ -23,14 +23,34 @@ public interface JsonProvider {
static final Object UNDEFINED = new Object();
/**
* Parse the given json string
* @param json json string to parse
* @return Object representation of json
* @throws InvalidJsonException
*/
Object parse(String json) throws InvalidJsonException;
/**
* Parse the given json string
* @param jsonStream input stream to parse
* @param charset charset to use
* @return Object representation of json
* @throws InvalidJsonException
*/
Object parse(InputStream jsonStream, String charset) throws InvalidJsonException;
/**
* Convert given json object to a json string
* @param obj object to transform
* @return json representation of object
*/
String toJson(Object obj);
Object createNull();
/**
* Creates a provider specific json array
* @return new array
*/
Object createArray();
/**

Loading…
Cancel
Save