Browse Source

Merge pull request #46 from jochenberger/cleanup-json-provider

remove some obsolete methods from the @JsonProvider@ interface
pull/47/head
kallestenflo 10 years ago
parent
commit
115b2a8c50
  1. 48
      json-path/src/main/java/com/jayway/jsonpath/internal/Utils.java
  2. 34
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/AbstractJsonProvider.java
  3. 5
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JacksonProvider.java
  4. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/spi/json/JsonSmartJsonProvider.java
  5. 21
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProvider.java

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

@ -266,54 +266,6 @@ public final class Utils {
//
//---------------------------------------------------------
/**
* <p>Deep clone an {@code Object} using serialization.</p>
* <p/>
* <p>This is many times slower than writing clone methods by hand
* on all objects in your object graph. However, for complex object
* graphs, or for those that don't support deep cloning this can
* be a simple alternative implementation. Of course all the objects
* must be {@code Serializable}.</p>
*
* @param <T> the type of the object involved
* @param object the {@code Serializable} object to clone
* @return the cloned object
*/
public static <T extends Serializable> T clone(T object) {
if (object == null) {
return null;
}
byte[] objectData = serialize(object);
ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
ClassLoaderAwareObjectInputStream in = null;
try {
// stream closed in the finally
in = new ClassLoaderAwareObjectInputStream(bais, object.getClass().getClassLoader());
/*
* when we serialize and deserialize an object,
* it is reasonable to assume the deserialized object
* is of the same type as the original serialized object
*/
@SuppressWarnings("unchecked") // see above
T readObject = (T) in.readObject();
return readObject;
} catch (ClassNotFoundException ex) {
throw new RuntimeException("ClassNotFoundException while reading cloned object data", ex);
} catch (IOException ex) {
throw new RuntimeException("IOException while reading cloned object data", ex);
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
throw new RuntimeException("IOException on closing cloned object data InputStream.", ex);
}
}
}
/**
* <p>Serializes an {@code Object} to the specified stream.</p>

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

@ -14,10 +14,8 @@
*/
package com.jayway.jsonpath.internal.spi.json;
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.spi.json.JsonProvider;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -25,21 +23,6 @@ import java.util.Map;
public abstract class AbstractJsonProvider implements JsonProvider {
@Override
public Object clone(Object obj) {
return Utils.clone((Serializable) obj);
}
/**
* checks if object is a map or an array
*
* @param obj object to check
* @return true if obj is a map or an array
*/
public boolean isContainer(Object obj) {
return (isArray(obj) || isMap(obj));
}
/**
* checks if object is an array
*
@ -90,23 +73,6 @@ public abstract class AbstractJsonProvider implements JsonProvider {
}
}
/**
* Extracts a value from an object or array
*
* @param obj an array or an object
* @param key a String key or a numerical index
* @return the entry at the given key, i.e. obj[key]
*/
public Object getProperty(Object obj, Object key) {
if (isMap(obj))
return ((Map) obj).get(key.toString());
else {
int index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
return ((List) obj).get(index);
}
}
/**
* Sets a value in an object or array
*

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

@ -18,7 +18,6 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.jayway.jsonpath.InvalidJsonException;
import com.jayway.jsonpath.spi.json.Mode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -66,10 +65,6 @@ public class JacksonProvider extends AbstractJsonProvider {
this.objectReader = objectReader;
}
public Mode getMode() {
return Mode.STRICT;
}
@Override
public Object parse(String json) throws InvalidJsonException {
try {

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

@ -89,10 +89,6 @@ public class JsonSmartJsonProvider extends AbstractJsonProvider {
}
}
public Mode getMode() {
return mode;
}
private JSONParser createParser() {
return new JSONParser(mode.intValue());
}

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

@ -24,8 +24,6 @@ public interface JsonProvider {
static final Object UNDEFINED = new Object();
Mode getMode();
Object parse(String json) throws InvalidJsonException;
Object parse(Reader jsonReader) throws InvalidJsonException;
@ -38,16 +36,6 @@ public interface JsonProvider {
Object createArray();
Object clone(Object model);
/**
* checks if object is a map or an array
*
* @param obj object to check
* @return true if obj is a map or an array
*/
boolean isContainer(Object obj);
/**
* checks if object is an array
*
@ -81,15 +69,6 @@ public interface JsonProvider {
*/
Collection<String> getPropertyKeys(Object obj);
/**
* Extracts a value from an object or array
*
* @param obj an array or an object
* @param key a String key or a numerical index
* @return the entry at the given key, i.e. obj[key]
*/
Object getProperty(Object obj, Object key);
/**
* Extracts a value from an array
*

Loading…
Cancel
Save