From 866cb9b11a50b31972b485a8d1623b9240c0eaa0 Mon Sep 17 00:00:00 2001 From: "wanglingsong@gmail.com" Date: Tue, 3 Nov 2015 00:39:51 +0800 Subject: [PATCH] v1.2.6 pre-release --- jsurfer-benchmark/pom.xml | 2 +- jsurfer-core/pom.xml | 2 +- .../java/org/jsfr/json/JsonDomBuilder.java | 12 ++++---- .../org/jsfr/json/TypedJsonPathListener.java | 3 -- ...eException.java => ResolverException.java} | 4 +-- .../java/org/jsfr/json/path/ArrayIndex.java | 4 +-- .../java/org/jsfr/json/path/ChildNode.java | 7 ++--- .../java/org/jsfr/json/path/JsonPath.java | 7 ++--- .../java/org/jsfr/json/path/PathOperator.java | 5 ++-- .../main/java/org/jsfr/json/path/Root.java | 4 +-- .../org/jsfr/json/provider/GsonProvider.java | 6 ++-- .../jsfr/json/provider/JacksonProvider.java | 4 +-- .../json/provider/JavaCollectionProvider.java | 4 +-- .../org/jsfr/json/provider/JsonProvider.java | 8 ++--- .../json/provider/JsonSimpleProvider.java | 4 +-- ...athResolver.java => DocumentResolver.java} | 2 +- .../org/jsfr/json/resolver/PoJoResolver.java | 8 ++--- .../json/{path => resolver}/Resolvable.java | 6 ++-- .../java/org/jsfr/json/JsonSurferTest.java | 30 +++++++++---------- pom.xml | 2 +- 20 files changed, 57 insertions(+), 67 deletions(-) rename jsurfer-core/src/main/java/org/jsfr/json/exception/{ResolveException.java => ResolverException.java} (90%) rename jsurfer-core/src/main/java/org/jsfr/json/resolver/{JsonPathResolver.java => DocumentResolver.java} (96%) rename jsurfer-core/src/main/java/org/jsfr/json/{path => resolver}/Resolvable.java (89%) diff --git a/jsurfer-benchmark/pom.xml b/jsurfer-benchmark/pom.xml index 3daa4c3..9d9c483 100644 --- a/jsurfer-benchmark/pom.xml +++ b/jsurfer-benchmark/pom.xml @@ -5,7 +5,7 @@ jsurfer com.github.jsurfer - 1.3.0-SNAPSHOT + 1.2.6 4.0.0 diff --git a/jsurfer-core/pom.xml b/jsurfer-core/pom.xml index 9c0c966..4165f5a 100644 --- a/jsurfer-core/pom.xml +++ b/jsurfer-core/pom.xml @@ -5,7 +5,7 @@ jsurfer com.github.jsurfer - 1.3.0-SNAPSHOT + 1.2.6 4.0.0 diff --git a/jsurfer-core/src/main/java/org/jsfr/json/JsonDomBuilder.java b/jsurfer-core/src/main/java/org/jsfr/json/JsonDomBuilder.java index 4127756..59614eb 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/JsonDomBuilder.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/JsonDomBuilder.java @@ -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; @@ -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; @@ -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; diff --git a/jsurfer-core/src/main/java/org/jsfr/json/TypedJsonPathListener.java b/jsurfer-core/src/main/java/org/jsfr/json/TypedJsonPathListener.java index 0b0e0e5..50921db 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/TypedJsonPathListener.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/TypedJsonPathListener.java @@ -24,9 +24,6 @@ package org.jsfr.json; -/** - * Created by Leo on 2015/4/28. - */ public interface TypedJsonPathListener { void onTypedValue(T value, ParsingContext context) throws Exception; diff --git a/jsurfer-core/src/main/java/org/jsfr/json/exception/ResolveException.java b/jsurfer-core/src/main/java/org/jsfr/json/exception/ResolverException.java similarity index 90% rename from jsurfer-core/src/main/java/org/jsfr/json/exception/ResolveException.java rename to jsurfer-core/src/main/java/org/jsfr/json/exception/ResolverException.java index 362d14d..e199945 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/exception/ResolveException.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/exception/ResolverException.java @@ -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); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/ArrayIndex.java b/jsurfer-core/src/main/java/org/jsfr/json/path/ArrayIndex.java index d16eff0..591a3b0 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/ArrayIndex.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/path/ArrayIndex.java @@ -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. @@ -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); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/ChildNode.java b/jsurfer-core/src/main/java/org/jsfr/json/path/ChildNode.java index ae31b28..81ca017 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/ChildNode.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/path/ChildNode.java @@ -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; @@ -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); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/JsonPath.java b/jsurfer-core/src/main/java/org/jsfr/json/path/JsonPath.java index d265ad2..76f2521 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/JsonPath.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/path/JsonPath.java @@ -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; @@ -34,7 +34,7 @@ import java.util.ListIterator; import java.util.Stack; -public class JsonPath implements Iterable, Resolvable { +public class JsonPath implements Iterable { @Override public Iterator iterator() { @@ -124,8 +124,7 @@ public JsonPath build() { protected Stack operators = new Stack(); - @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."); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/PathOperator.java b/jsurfer-core/src/main/java/org/jsfr/json/path/PathOperator.java index 16c9911..4689b69 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/PathOperator.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/path/PathOperator.java @@ -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 { @@ -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"); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/Root.java b/jsurfer-core/src/main/java/org/jsfr/json/path/Root.java index 0f3d66c..1cb274d 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/Root.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/path/Root.java @@ -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 { @@ -38,7 +38,7 @@ private Root() { } @Override - public Object resolve(Object document, JsonPathResolver resolver) { + public Object resolve(Object document, DocumentResolver resolver) { return document; } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/provider/GsonProvider.java b/jsurfer-core/src/main/java/org/jsfr/json/provider/GsonProvider.java index e3598d2..896ab64 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/provider/GsonProvider.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/provider/GsonProvider.java @@ -39,7 +39,7 @@ public class GsonProvider implements JsonProvider object, String key, Object value) { + public void put(Map object, String key, Object value) { object.put(key, value); } @Override - public void consumeArrayElement(List array, Object value) { + public void add(List array, Object value) { array.add(value); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonProvider.java b/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonProvider.java index b2a60dc..928a873 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonProvider.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonProvider.java @@ -24,9 +24,9 @@ package org.jsfr.json.provider; -import org.jsfr.json.resolver.JsonPathResolver; +import org.jsfr.json.resolver.DocumentResolver; -public interface JsonProvider extends JsonPathResolver { +public interface JsonProvider extends DocumentResolver { O createObject(); @@ -36,9 +36,9 @@ public interface JsonProvider extends JsonPathResolver { 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); diff --git a/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonSimpleProvider.java b/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonSimpleProvider.java index b53d358..2f272b2 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonSimpleProvider.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/provider/JsonSimpleProvider.java @@ -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); } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/resolver/JsonPathResolver.java b/jsurfer-core/src/main/java/org/jsfr/json/resolver/DocumentResolver.java similarity index 96% rename from jsurfer-core/src/main/java/org/jsfr/json/resolver/JsonPathResolver.java rename to jsurfer-core/src/main/java/org/jsfr/json/resolver/DocumentResolver.java index 892bead..9754b59 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/resolver/JsonPathResolver.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/resolver/DocumentResolver.java @@ -24,7 +24,7 @@ package org.jsfr.json.resolver; -public interface JsonPathResolver { +public interface DocumentResolver { Object resolve(O object, String key); diff --git a/jsurfer-core/src/main/java/org/jsfr/json/resolver/PoJoResolver.java b/jsurfer-core/src/main/java/org/jsfr/json/resolver/PoJoResolver.java index 731343e..bfdbef6 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/resolver/PoJoResolver.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/resolver/PoJoResolver.java @@ -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 { +public class PoJoResolver implements DocumentResolver { @Override public Object resolve(Object object, String field) { @@ -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; } diff --git a/jsurfer-core/src/main/java/org/jsfr/json/path/Resolvable.java b/jsurfer-core/src/main/java/org/jsfr/json/resolver/Resolvable.java similarity index 89% rename from jsurfer-core/src/main/java/org/jsfr/json/path/Resolvable.java rename to jsurfer-core/src/main/java/org/jsfr/json/resolver/Resolvable.java index 759dc54..952bec1 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/path/Resolvable.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/resolver/Resolvable.java @@ -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); } diff --git a/jsurfer-core/src/test/java/org/jsfr/json/JsonSurferTest.java b/jsurfer-core/src/test/java/org/jsfr/json/JsonSurferTest.java index 87ae4a9..795b36f 100644 --- a/jsurfer-core/src/test/java/org/jsfr/json/JsonSurferTest.java +++ b/jsurfer-core/src/test/java/org/jsfr/json/JsonSurferTest.java @@ -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; @@ -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)); } @@ -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)); diff --git a/pom.xml b/pom.xml index a375a66..ca9d829 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.github.jsurfer jsurfer - 1.3.0-SNAPSHOT + 1.2.6 pom JsonSurfer Let's surf on json