Skip to content

Commit

Permalink
v1.2.6 pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglingsong committed Nov 2, 2015
1 parent a905ac3 commit 866cb9b
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 67 deletions.
2 changes: 1 addition & 1 deletion jsurfer-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsurfer</artifactId>
<groupId>com.github.jsurfer</groupId>
<version>1.3.0-SNAPSHOT</version>
<version>1.2.6</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion jsurfer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsurfer</artifactId>
<groupId>com.github.jsurfer</groupId>
<version>1.3.0-SNAPSHOT</version>
<version>1.2.6</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
12 changes: 6 additions & 6 deletions jsurfer-core/src/main/java/org/jsfr/json/JsonDomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public boolean startObject() {
Object newObject = provider.createObject();
switch (scope) {
case IN_OBJECT:
provider.consumeObjectEntry(currentNode, propertyName, newObject);
provider.put(currentNode, propertyName, newObject);
break;
case IN_ARRAY:
provider.consumeArrayElement(currentNode, newObject);
provider.add(currentNode, newObject);
break;
case IN_ROOT:
break;
Expand Down Expand Up @@ -127,10 +127,10 @@ public boolean startArray() {
Object newArray = provider.createArray();
switch (scope) {
case IN_OBJECT:
provider.consumeObjectEntry(currentNode, propertyName, newArray);
provider.put(currentNode, propertyName, newArray);
break;
case IN_ARRAY:
provider.consumeArrayElement(currentNode, newArray);
provider.add(currentNode, newArray);
break;
case IN_ROOT:
break;
Expand All @@ -150,10 +150,10 @@ public boolean endArray() {
private void consumePrimitive(Object value) {
switch (scope) {
case IN_OBJECT:
provider.consumeObjectEntry(currentNode, propertyName, value);
provider.put(currentNode, propertyName, value);
break;
case IN_ARRAY:
provider.consumeArrayElement(currentNode, value);
provider.add(currentNode, value);
break;
case IN_ROOT:
currentNode = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

package org.jsfr.json;

/**
* Created by Leo on 2015/4/28.
*/
public interface TypedJsonPathListener<T> {

void onTypedValue(T value, ParsingContext context) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

package org.jsfr.json.exception;

public class ResolveException extends RuntimeException {
public class ResolverException extends RuntimeException {

public ResolveException(String message, Throwable cause) {
public ResolverException(String message, Throwable cause) {
super(message, cause);
}

Expand Down
4 changes: 2 additions & 2 deletions jsurfer-core/src/main/java/org/jsfr/json/path/ArrayIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;

/**
* Created by Administrator on 2015/3/22.
Expand Down Expand Up @@ -63,7 +63,7 @@ public boolean match(PathOperator pathOperator) {
}

@Override
public Object resolve(Object document, JsonPathResolver resolver) {
public Object resolve(Object document, DocumentResolver resolver) {
return resolver.resolve(document, arrayIndex);
}

Expand Down
7 changes: 2 additions & 5 deletions jsurfer-core/src/main/java/org/jsfr/json/path/ChildNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;

import java.util.Objects;

/**
* Created by Administrator on 2015/3/22.
*/
public class ChildNode extends PathOperator {

private String key;
Expand All @@ -53,7 +50,7 @@ public boolean match(PathOperator pathOperator) {
}

@Override
public Object resolve(Object document, JsonPathResolver resolver) {
public Object resolve(Object document, DocumentResolver resolver) {
return resolver.resolve(document, key);
}

Expand Down
7 changes: 3 additions & 4 deletions jsurfer-core/src/main/java/org/jsfr/json/path/JsonPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -34,7 +34,7 @@
import java.util.ListIterator;
import java.util.Stack;

public class JsonPath implements Iterable<PathOperator>, Resolvable {
public class JsonPath implements Iterable<PathOperator> {

@Override
public Iterator<PathOperator> iterator() {
Expand Down Expand Up @@ -124,8 +124,7 @@ public JsonPath build() {

protected Stack<PathOperator> operators = new Stack<PathOperator>();

@Override
public Object resolve(Object document, JsonPathResolver resolver) {
public Object resolve(Object document, DocumentResolver resolver) {
if (!this.isDefinite()) {
throw new IllegalArgumentException("Indefinite JsonPath is not supported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;
import org.jsfr.json.resolver.Resolvable;

public abstract class PathOperator implements Resolvable {

Expand All @@ -44,7 +45,7 @@ public boolean match(PathOperator pathOperator) {
}

@Override
public Object resolve(Object document, JsonPathResolver resolver) {
public Object resolve(Object document, DocumentResolver resolver) {
throw new UnsupportedOperationException("Not supported");
}

Expand Down
4 changes: 2 additions & 2 deletions jsurfer-core/src/main/java/org/jsfr/json/path/Root.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;

public class Root extends PathOperator {

Expand All @@ -38,7 +38,7 @@ private Root() {
}

@Override
public Object resolve(Object document, JsonPathResolver resolver) {
public Object resolve(Object document, DocumentResolver resolver) {
return document;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class GsonProvider implements JsonProvider<JsonObject, JsonArray, JsonEle
private Gson internalGson;

public GsonProvider() {
this.internalGson = new GsonBuilder().create();
this(new GsonBuilder().create());
}

public GsonProvider(Gson internalGson) {
Expand Down Expand Up @@ -67,12 +67,12 @@ public boolean isArray(Object array) {
}

@Override
public void consumeObjectEntry(JsonObject object, String key, JsonElement value) {
public void put(JsonObject object, String key, JsonElement value) {
object.add(key, value);
}

@Override
public void consumeArrayElement(JsonArray array, JsonElement value) {
public void add(JsonArray array, JsonElement value) {
array.add(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public boolean isArray(Object array) {
}

@Override
public void consumeObjectEntry(ObjectNode object, String key, JsonNode value) {
public void put(ObjectNode object, String key, JsonNode value) {
object.set(key, value);
}

@Override
public void consumeArrayElement(ArrayNode array, JsonNode value) {
public void add(ArrayNode array, JsonNode value) {
array.add(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public boolean isArray(Object array) {
}

@Override
public void consumeObjectEntry(Map<String, Object> object, String key, Object value) {
public void put(Map<String, Object> object, String key, Object value) {
object.put(key, value);
}

@Override
public void consumeArrayElement(List<Object> array, Object value) {
public void add(List<Object> array, Object value) {
array.add(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

package org.jsfr.json.provider;

import org.jsfr.json.resolver.JsonPathResolver;
import org.jsfr.json.resolver.DocumentResolver;

public interface JsonProvider<O, A, P> extends JsonPathResolver<O, A> {
public interface JsonProvider<O, A, P> extends DocumentResolver<O, A> {

O createObject();

Expand All @@ -36,9 +36,9 @@ public interface JsonProvider<O, A, P> extends JsonPathResolver<O, A> {

boolean isArray(Object array);

void consumeObjectEntry(O object, String key, P value);
void put(O object, String key, P value);

void consumeArrayElement(A array, P value);
void add(A array, P value);

P primitive(boolean value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public boolean isArray(Object array) {
}

@Override
public void consumeObjectEntry(JSONObject object, String key, Object value) {
public void put(JSONObject object, String key, Object value) {
object.put(key, value);
}

@Override
public void consumeArrayElement(JSONArray array, Object value) {
public void add(JSONArray array, Object value) {
array.add(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package org.jsfr.json.resolver;

public interface JsonPathResolver<O, L> {
public interface DocumentResolver<O, L> {

Object resolve(O object, String key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

package org.jsfr.json.resolver;

import org.jsfr.json.exception.ResolveException;
import org.jsfr.json.exception.ResolverException;

import java.lang.reflect.Field;
import java.util.List;

public class PoJoResolver implements JsonPathResolver<Object, Object> {
public class PoJoResolver implements DocumentResolver<Object, Object> {

@Override
public Object resolve(Object object, String field) {
Expand All @@ -39,9 +39,9 @@ public Object resolve(Object object, String field) {
declaredField.setAccessible(true);
value = declaredField.get(object);
} catch (IllegalAccessException e) {
throw new ResolveException("Failed to resolve field: " + field, e);
throw new ResolverException("Failed to resolve field: " + field, e);
} catch (NoSuchFieldException e) {
throw new ResolveException("Failed to resolve field: " + field, e);
throw new ResolverException("Failed to resolve field: " + field, e);
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
* THE SOFTWARE.
*/

package org.jsfr.json.path;

import org.jsfr.json.resolver.JsonPathResolver;
package org.jsfr.json.resolver;

public interface Resolvable {

Object resolve(Object document, JsonPathResolver resolver);
Object resolve(Object document, DocumentResolver resolver);

}
30 changes: 14 additions & 16 deletions jsurfer-core/src/test/java/org/jsfr/json/JsonSurferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -86,22 +84,22 @@ public void testSampleJson() throws Exception {
surfer.surf(read("sample.json"), builder.build());

Object book = provider.createObject();
provider.consumeObjectEntry(book, "category", provider.primitive("reference"));
provider.consumeObjectEntry(book, "author", provider.primitive("Nigel Rees"));
provider.consumeObjectEntry(book, "title", provider.primitive("Sayings of the Century"));
provider.consumeObjectEntry(book, "price", provider.primitive(8.95));
provider.put(book, "category", provider.primitive("reference"));
provider.put(book, "author", provider.primitive("Nigel Rees"));
provider.put(book, "title", provider.primitive("Sayings of the Century"));
provider.put(book, "price", provider.primitive(8.95));
verify(mockListener).onValue(eq(book), any(ParsingContext.class));

verify(mockListener).onValue(eq(provider.primitive("reference")), any(ParsingContext.class));

Object cars = provider.createArray();
provider.consumeArrayElement(cars, provider.primitive("ferrari"));
provider.consumeArrayElement(cars, provider.primitive("lamborghini"));
provider.add(cars, provider.primitive("ferrari"));
provider.add(cars, provider.primitive("lamborghini"));
verify(mockListener).onValue(eq(cars), any(ParsingContext.class));

Object bicycle = provider.createObject();
provider.consumeObjectEntry(bicycle, "color", provider.primitive("red"));
provider.consumeObjectEntry(bicycle, "price", provider.primitive(19.95d));
provider.put(bicycle, "color", provider.primitive("red"));
provider.put(bicycle, "price", provider.primitive(19.95d));
verify(mockListener).onValue(eq(bicycle), any(ParsingContext.class));
}

Expand Down Expand Up @@ -214,13 +212,13 @@ public void testParsingArray() throws Exception {
builder.bind("$[4]", objectElement);
surfer.surf(read("array.json"), builder.build());
Object object = provider.createObject();
provider.consumeObjectEntry(object, "key", provider.primitive("value"));
provider.put(object, "key", provider.primitive("value"));
Object array = provider.createArray();
provider.consumeArrayElement(array, provider.primitive("abc"));
provider.consumeArrayElement(array, provider.primitive(8.88));
provider.consumeArrayElement(array, provider.primitive(true));
provider.consumeArrayElement(array, provider.primitiveNull());
provider.consumeArrayElement(array, object);
provider.add(array, provider.primitive("abc"));
provider.add(array, provider.primitive(8.88));
provider.add(array, provider.primitive(true));
provider.add(array, provider.primitiveNull());
provider.add(array, object);
verify(wholeArray).onValue(eq(array), any(ParsingContext.class));
verify(stringElement).onValue(eq(provider.primitive("abc")), any(ParsingContext.class));
verify(numberElement).onValue(eq(provider.primitive(8.88)), any(ParsingContext.class));
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.jsurfer</groupId>
<artifactId>jsurfer</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.2.6</version>
<packaging>pom</packaging>
<name>JsonSurfer</name>
<description>Let's surf on json</description>
Expand Down

0 comments on commit 866cb9b

Please sign in to comment.