Browse Source

Merge pull request #48 from jochenberger/remove-json-provider-factory

remove `JsonProviderFactory`, the `JsonProvider` should be set via `Configuration`
pull/49/head
kallestenflo 10 years ago
parent
commit
fb19598dbe
  1. 8
      json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java
  2. 3
      json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java
  3. 4
      json-path/src/main/java/com/jayway/jsonpath/Configuration.java
  4. 9
      json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
  5. 46
      json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProviderFactory.java
  6. 9
      json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java
  7. 5
      json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java
  8. 5
      json-path/src/test/java/com/jayway/jsonpath/old/JsonPathTest.java
  9. 7
      json-path/src/test/java/com/jayway/jsonpath/old/internal/PredicatePathTokenTest.java
  10. 7
      json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java
  11. 6
      json-path/src/test/java/com/jayway/jsonpath/old/internal/TestBase.java

8
json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java

@ -7,7 +7,9 @@ import com.jayway.jsonassert.impl.matcher.IsCollectionWithSize;
import com.jayway.jsonassert.impl.matcher.IsEmptyCollection;
import com.jayway.jsonassert.impl.matcher.IsMapContainingKey;
import com.jayway.jsonassert.impl.matcher.IsMapContainingValue;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import org.hamcrest.Matcher;
import java.io.IOException;
@ -30,7 +32,7 @@ public class JsonAssert {
* @throws ParseException when the given JSON could not be parsed
*/
public static JsonAsserter with(String json) {
return new JsonAsserterImpl(JsonProviderFactory.createProvider().parse(json));
return new JsonAsserterImpl(JsonPath.parse(json).json());
}
/**
@ -41,7 +43,7 @@ public class JsonAssert {
* @throws ParseException when the given JSON could not be parsed
*/
public static JsonAsserter with(Reader reader) throws IOException {
return new JsonAsserterImpl(JsonProviderFactory.createProvider().parse(convertReaderToString(reader)));
return new JsonAsserterImpl(JsonPath.parse(convertReaderToString(reader)).json());
}

3
json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java

@ -4,7 +4,6 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.internal.spi.json.JacksonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import io.gatling.jsonpath.JsonPath$;
import org.boon.json.JsonParser;
import org.boon.json.ObjectMapper;
@ -71,7 +70,7 @@ public class Bench {
} else if (res instanceof Boolean) {
result = res.toString();
} else {
result = res != null ? JsonProviderFactory.createProvider().toJson(res) : "null";
result = res != null ? Configuration.defaultConfiguration().getProvider().toJson(res) : "null";
}
return new Result("jayway", time, result, error);
}

4
json-path/src/main/java/com/jayway/jsonpath/Configuration.java

@ -14,8 +14,8 @@
*/
package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import java.util.Collections;
import java.util.EnumSet;
@ -29,7 +29,7 @@ public class Configuration {
private static Defaults DEFAULTS = new Defaults() {
@Override
public JsonProvider provider() {
return JsonProviderFactory.createProvider();
return new JsonSmartJsonProvider();
}
@Override

9
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

@ -21,7 +21,6 @@ import com.jayway.jsonpath.internal.PathCompiler;
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.spi.http.HttpProviderFactory;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import java.io.File;
import java.io.FileInputStream;
@ -314,13 +313,7 @@ public class JsonPath {
*/
@SuppressWarnings({"unchecked"})
public <T> T read(InputStream jsonInputStream) throws IOException {
notNull(jsonInputStream, "json input stream can not be null");
try {
return read(JsonProviderFactory.createProvider().parse(jsonInputStream));
} finally {
Utils.closeQuietly(jsonInputStream);
}
return read(jsonInputStream, Configuration.defaultConfiguration());
}
/**

46
json-path/src/main/java/com/jayway/jsonpath/spi/json/JsonProviderFactory.java

@ -1,46 +0,0 @@
/*
* 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.spi.json;
public abstract class JsonProviderFactory {
private static JsonProvider provider = null;
private static final String DEFAULT_JSON_PROVIDER = "com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider";
//private static final String DEFAULT_JSON_PROVIDER = "com.jayway.jsonpath.internal.spi.json.JacksonProvider";
public static JsonProvider createProvider() {
if(provider == null){
synchronized (JsonProviderFactory.class){
if(provider == null){
try {
provider = (JsonProvider) Class.forName(DEFAULT_JSON_PROVIDER).newInstance();
} catch (Exception e) {
throw new RuntimeException("Failed to create JsonProvider", e);
}
}
}
}
return provider;
}
public static synchronized void setProvider(JsonProvider jsonProvider) {
provider = jsonProvider;
}
}

9
json-path/src/test/java/com/jayway/jsonpath/old/FilterTest.java

@ -6,8 +6,9 @@ import com.jayway.jsonpath.Filter;
import com.jayway.jsonpath.InvalidCriteriaException;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import org.junit.Test;
import java.util.Collections;
@ -60,7 +61,7 @@ public class FilterTest extends BaseTest {
" }\n" +
"}";
private static final JsonProvider jp = JsonProviderFactory.createProvider();
private static final JsonProvider jp = new JsonSmartJsonProvider();
private static final Configuration conf = Configuration.defaultConfiguration();
//-------------------------------------------------
@ -380,7 +381,7 @@ public class FilterTest extends BaseTest {
@Test
public void filters_can_contain_json_path_expressions() throws Exception {
Object doc = JsonProviderFactory.createProvider().parse(DOCUMENT);
Object doc = new JsonSmartJsonProvider().parse(DOCUMENT);
assertFalse(filter(where("$.store.bicycle.color").ne("red")).apply(createPredicateContext(doc)));
}
@ -410,7 +411,7 @@ public class FilterTest extends BaseTest {
"}\n";
Object doc = JsonProviderFactory.createProvider().parse(json);
Object doc = new JsonSmartJsonProvider().parse(json);
List<Map<String, Object>> result = JsonPath.read(doc, "$.fields[?]", filter(where("errors").notEmpty()));
assertEquals(1, result.size());

5
json-path/src/test/java/com/jayway/jsonpath/old/IssuesTest.java

@ -7,8 +7,9 @@ import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.internal.Utils;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import org.assertj.core.api.Assertions;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -27,7 +28,7 @@ import static org.junit.Assert.assertThat;
public class IssuesTest {
private static final JsonProvider jp = JsonProviderFactory.createProvider();
private static final JsonProvider jp = new JsonSmartJsonProvider();
@Test
public void full_ones_can_be_filtered() {

5
json-path/src/test/java/com/jayway/jsonpath/old/JsonPathTest.java

@ -4,7 +4,8 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.internal.PathCompiler;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import org.assertj.core.api.Assertions;
import org.junit.Test;
@ -60,7 +61,7 @@ public class JsonPathTest {
" }\n" +
"}";
public final static Object OBJ_DOCUMENT = JsonProviderFactory.createProvider().parse(DOCUMENT);
public final static Object OBJ_DOCUMENT = new JsonSmartJsonProvider().parse(DOCUMENT);
private final static String PRODUCT_JSON = "{\n" +

7
json-path/src/test/java/com/jayway/jsonpath/old/internal/PredicatePathTokenTest.java

@ -1,7 +1,8 @@
package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import org.junit.Test;
import java.util.List;
@ -13,7 +14,7 @@ import static org.assertj.core.api.Assertions.entry;
public class PredicatePathTokenTest {
private static final Object ARRAY = JsonProviderFactory.createProvider().parse(
private static final Object ARRAY = new JsonSmartJsonProvider().parse(
"[" +
"{\n" +
" \"foo\" : \"foo-val-0\"\n" +
@ -38,7 +39,7 @@ public class PredicatePathTokenTest {
"}" +
"]");
private static Object ARRAY2 = JsonProviderFactory.createProvider().parse(
private static Object ARRAY2 = new JsonSmartJsonProvider().parse(
"[" +
"{\n" +
" \"foo\" : \"foo-val-0\",\n" +

7
json-path/src/test/java/com/jayway/jsonpath/old/internal/ScanPathTokenTest.java

@ -3,7 +3,8 @@ package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.internal.PathCompiler;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
import org.junit.Test;
import java.util.List;
@ -14,7 +15,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ScanPathTokenTest {
public final static Object DOCUMENT = JsonProviderFactory.createProvider().parse(
public final static Object DOCUMENT = new JsonSmartJsonProvider().parse(
"{\n" +
" \"store\":{\n" +
" \"book\":[\n" +
@ -63,7 +64,7 @@ public class ScanPathTokenTest {
"}"
);
public final static Object DOCUMENT2 = JsonProviderFactory.createProvider().parse(
public final static Object DOCUMENT2 = new JsonSmartJsonProvider().parse(
"{\n" +
" \"firstName\": \"John\",\n" +
" \"lastName\" : \"doe\",\n" +

6
json-path/src/test/java/com/jayway/jsonpath/old/internal/TestBase.java

@ -1,7 +1,7 @@
package com.jayway.jsonpath.old.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.spi.json.JsonProviderFactory;
import com.jayway.jsonpath.internal.spi.json.JsonSmartJsonProvider;
/**
*
@ -9,7 +9,7 @@ import com.jayway.jsonpath.spi.json.JsonProviderFactory;
public class TestBase {
public final static Object ARRAY = JsonProviderFactory.createProvider().parse("[" +
public final static Object ARRAY = new JsonSmartJsonProvider().parse("[" +
"{\n" +
" \"foo\" : \"foo-val-0\"\n" +
"}," +
@ -33,7 +33,7 @@ public class TestBase {
"}" +
"]");
public final static Object DOC = JsonProviderFactory.createProvider().parse(
public final static Object DOC = new JsonSmartJsonProvider().parse(
"{ \"store\": {\n" +
" \"book\": [ \n" +
" { \"category\": \"reference\",\n" +

Loading…
Cancel
Save