diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java index 22277d2b..999b2c68 100644 --- a/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java +++ b/json-path-assert/src/main/java/com/jayway/jsonassert/JsonAssert.java @@ -4,6 +4,7 @@ package com.jayway.jsonassert; import com.jayway.jsonassert.impl.JsonAsserterImpl; import com.jayway.jsonassert.impl.matcher.*; import com.jayway.jsonpath.spi.JsonProvider; +import com.jayway.jsonpath.spi.JsonProviderFactory; import org.hamcrest.Matcher; import java.io.*; @@ -18,7 +19,7 @@ import java.util.Map; */ public class JsonAssert { - private static JsonProvider jsonProvider = JsonProvider.getInstance(); + private static JsonProvider jsonProvider = JsonProviderFactory.getInstance(); public static void setJsonProvider(JsonProvider jsonProvider) { JsonAssert.jsonProvider = jsonProvider; diff --git a/json-path/pom.xml b/json-path/pom.xml index 86e83de8..d94b0baf 100644 --- a/json-path/pom.xml +++ b/json-path/pom.xml @@ -40,10 +40,15 @@ commons-lang + + commons-io + commons-io + + org.codehaus.jackson jackson-mapper-asl - provided + true @@ -66,13 +71,13 @@ - - - - org.apache.felix - maven-bundle-plugin - true - - - + + + + org.apache.felix + maven-bundle-plugin + true + + + diff --git a/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java b/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java index 5c2aae5d..a324c377 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java +++ b/json-path/src/main/java/com/jayway/jsonpath/InvalidJsonException.java @@ -1,12 +1,23 @@ +/* + * 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; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 4:01 PM + * @author Kalle Stenflo */ -public class InvalidJsonException extends RuntimeException{ +public class InvalidJsonException extends RuntimeException { public InvalidJsonException() { } diff --git a/json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java b/json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java index e95e7431..c28cb8b5 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java +++ b/json-path/src/main/java/com/jayway/jsonpath/InvalidPathException.java @@ -1,9 +1,21 @@ +/* + * 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; /** - * User: kalle stenflo - * Date: 1/24/11 - * Time: 10:09 AM + * @author Kalle Stenflo */ public class InvalidPathException extends RuntimeException { diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonModel.java b/json-path/src/main/java/com/jayway/jsonpath/JsonModel.java index 73af18fc..778eb03c 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonModel.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonModel.java @@ -1,63 +1,152 @@ +/* + * 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; -import com.jayway.jsonpath.spi.JsonProvider; +import com.jayway.jsonpath.spi.JsonProviderFactory; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.type.CollectionType; + +import java.util.List; +import java.util.Set; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 7:40 PM + * @author Kalle Stenflo */ public class JsonModel { + private static ObjectMapper objectMapper; + private Object jsonObject; - private JsonProvider jsonProvider; + // -------------------------------------------------------- + // + // Constructors + // + // -------------------------------------------------------- public JsonModel(String json) { - this.jsonProvider = JsonProvider.getInstance(); - this.jsonObject = jsonProvider.parse(json); + this(JsonProviderFactory.getInstance().parse(json)); } private JsonModel(Object jsonObject) { - this.jsonProvider = JsonProvider.getInstance(); this.jsonObject = jsonObject; } - public static JsonModel create(String json) { - return new JsonModel(json); - } - + @SuppressWarnings({"unchecked"}) public T get(String jsonPath) { - JsonPath path = JsonPath.compile(jsonProvider, jsonPath); + JsonPath path = JsonPath.compile(jsonPath); return (T) get(path); } + @SuppressWarnings({"unchecked"}) public T get(JsonPath jsonPath) { return (T) jsonPath.read(jsonObject); } + public String getJson() { + return JsonProviderFactory.getInstance().toJson(jsonObject); + } + + public String getJson(String jsonPath) { + return JsonProviderFactory.getInstance().toJson(get(jsonPath)); + } + public String getJson(JsonPath jsonPath) { - return jsonProvider.toJson(jsonPath.read(jsonObject)); + return JsonProviderFactory.getInstance().toJson(get(jsonPath)); } - public JsonModel getModel(String jsonPath) { - JsonPath path = JsonPath.compile(jsonProvider, jsonPath); - return getModel(path); + public JsonModel getSubModel(String jsonPath) { + JsonPath path = JsonPath.compile(jsonPath); + return getSubModel(path); } - public JsonModel getModel(JsonPath jsonPath) { + public JsonModel getSubModel(JsonPath jsonPath) { Object subModel = jsonPath.read(jsonObject); - return new JsonModel(subModel); } - public JsonProvider getJsonProvider() { - return jsonProvider; + + public MappingModelReader map(final String jsonPath) { + + return new MappingModelReader() { + + private ObjectMapper objectMapper = JsonModel.getObjectMapper(); + + @Override + public List toListOf(Class targetClass) { + Object model = JsonModel.this.get(jsonPath); + CollectionType colType = objectMapper.getTypeFactory().constructCollectionType(List.class, targetClass); + return objectMapper.convertValue(model, colType); + } + + @Override + public Set toSetOf(Class targetClass) { + Object model = JsonModel.this.get(jsonPath); + CollectionType colType = objectMapper.getTypeFactory().constructCollectionType(Set.class, targetClass); + return objectMapper.convertValue(model, colType); + } + + @Override + public T to(Class targetClass) { + Object model = JsonModel.this.get(jsonPath); + return objectMapper.convertValue(model, targetClass); + } + }; + } + + // -------------------------------------------------------- + // + // Static factory methods + // + // -------------------------------------------------------- + public static JsonModel create(String json) { + return new JsonModel(json); + } + + public static JsonModel create(Object jsonObject) { + return new JsonModel(jsonObject); } - - public String getJson(){ - return jsonProvider.toJson(jsonObject); + + + // -------------------------------------------------------- + // + // Support interfaces + // + // -------------------------------------------------------- + public interface MappingModelReader { + List toListOf(Class targetClass); + + Set toSetOf(Class targetClass); + + T to(Class targetClass); } + + // -------------------------------------------------------- + // + // Private helpers + // + // -------------------------------------------------------- + private static ObjectMapper getObjectMapper() { + if (JsonModel.objectMapper == null) { + synchronized (JsonModel.class) { + JsonModel.objectMapper = new ObjectMapper(); + } + } + return JsonModel.objectMapper; + } + + } diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index d600f384..494ac769 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -1,19 +1,33 @@ +/* + * 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; -import com.jayway.jsonpath.reader.PathToken; -import com.jayway.jsonpath.reader.PathTokenizer; -import com.jayway.jsonpath.reader.filter.Filter; -import com.jayway.jsonpath.spi.JsonProvider; +import com.jayway.jsonpath.internal.PathToken; +import com.jayway.jsonpath.internal.PathTokenizer; +import com.jayway.jsonpath.internal.filter.Filter; +import com.jayway.jsonpath.spi.JsonProviderFactory; +import org.apache.commons.io.IOUtils; +import java.io.*; +import java.net.URL; import java.util.List; import java.util.Map; import java.util.regex.Pattern; /** - * User: kalle stenflo - * Date: 2/2/11 - * Time: 1:03 PM *

* JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPath is * available in many programming languages such as Javascript, Python and PHP. @@ -71,6 +85,8 @@ import java.util.regex.Pattern; * * String author = JsonPath.read(json, "$.store.book[1].author") * + * + * @author Kalle Stenflo */ public class JsonPath { @@ -78,29 +94,14 @@ public class JsonPath { private PathTokenizer tokenizer; - private JsonProvider jsonProvider; - - - /** - * Creates a new JsonPath. - * - * @param jsonPath the path statement - */ private JsonPath(String jsonPath) { - this(JsonProvider.getInstance(), jsonPath); - } - - - private JsonPath(JsonProvider jsonProvider, String jsonPath) { if (jsonPath == null || jsonPath.trim().isEmpty() || - jsonPath.matches("new ") || jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\(")) { throw new InvalidPathException("Invalid path"); } - this.jsonProvider = jsonProvider; - this.tokenizer = new PathTokenizer(jsonPath, jsonProvider); + this.tokenizer = new PathTokenizer(jsonPath); } public String getPath() { @@ -128,55 +129,115 @@ public class JsonPath { * @return true if path is definite (points to single item) */ public boolean isPathDefinite() { - //return !getPath().replaceAll("\"[^\"\\\\\\n\r]*\"", "").matches(".*(\\.\\.|\\*|\\[[\\\\/]|\\?|,|:\\s?\\]|\\[\\s?:|>|\\(|<|=|\\+).*"); - String preparedPath = getPath().replaceAll("\"[^\"\\\\\\n\r]*\"", ""); return !DEFINITE_PATH_PATTERN.matcher(preparedPath).matches(); - } /** - * Applies this container path to the provided object + * Applies this JsonPath to the provided json document. + * Note that the document must either a {@link List} or a {@link Map} * - * @param container a container Object - * @param + * @param json a container Object ({@link List} or {@link Map}) + * @param expected return type * @return list of objects matched by the given path */ - public T read(Object container) { - if (!(container instanceof Map) && !(container instanceof List)) { + @SuppressWarnings({"unchecked"}) + public T read(Object json) { + if (!(json instanceof Map) && !(json instanceof List)) { throw new IllegalArgumentException("Invalid container object"); } - Object result = container; + Object result = json; boolean inArrayContext = false; for (PathToken pathToken : tokenizer) { Filter filter = pathToken.getFilter(); - result = filter.filter(result, jsonProvider, inArrayContext); + result = filter.filter(result, JsonProviderFactory.getInstance(), inArrayContext); if (!inArrayContext) { inArrayContext = filter.isArrayFilter(); } - //result = pathToken.filter(result, jsonProvider); } return (T) result; } /** - * Applies this json path to the provided object + * Applies this JsonPath to the provided json string * * @param json a json string - * @param + * @param expected return type * @return list of objects matched by the given path */ + @SuppressWarnings({"unchecked"}) public T read(String json) { - return (T) read(jsonProvider.parse(json)); + return (T) read(JsonProviderFactory.getInstance().parse(json)); + } + + /** + * Applies this JsonPath to the provided json URL + * + * @param jsonURL url to read from + * @param expected return type + * @return list of objects matched by the given path + * @throws IOException + */ + @SuppressWarnings({"unchecked"}) + public T read(URL jsonURL) throws IOException { + BufferedReader in = null; + try { + in = new BufferedReader(new InputStreamReader(jsonURL.openStream())); + return (T) read(JsonProviderFactory.getInstance().parse(in)); + } finally { + IOUtils.closeQuietly(in); + } } /** - * Compiles a JsonPath from the given string + * Applies this JsonPath to the provided json file + * + * @param jsonFile file to read from + * @param expected return type + * @return list of objects matched by the given path + * @throws IOException + */ + @SuppressWarnings({"unchecked"}) + public T read(File jsonFile) throws IOException { + FileInputStream fis = null; + try { + fis = new FileInputStream(jsonFile); + return (T) read(JsonProviderFactory.getInstance().parse(fis)); + } finally { + IOUtils.closeQuietly(fis); + } + } + + /** + * Applies this JsonPath to the provided json input stream + * + * @param jsonInputStream input stream to read from + * @param expected return type + * @return list of objects matched by the given path + * @throws IOException + */ + @SuppressWarnings({"unchecked"}) + public T read(InputStream jsonInputStream) throws IOException { + try { + return (T) read(JsonProviderFactory.getInstance().parse(jsonInputStream)); + } finally { + IOUtils.closeQuietly(jsonInputStream); + } + } + + // -------------------------------------------------------- + // + // Static factory methods + // + // -------------------------------------------------------- + + /** + * Compiles a JsonPath * * @param jsonPath to compile * @return compiled JsonPath @@ -185,18 +246,22 @@ public class JsonPath { return new JsonPath(jsonPath); } - public static JsonPath compile(JsonProvider provider, String jsonPath) { - return new JsonPath(provider, jsonPath); - } + + // -------------------------------------------------------- + // + // Static utility functions + // + // -------------------------------------------------------- /** * Creates a new JsonPath and applies it to the provided Json string * * @param json a json string * @param jsonPath the json path - * @param + * @param expected return type * @return list of objects matched by the given path */ + @SuppressWarnings({"unchecked"}) public static T read(String json, String jsonPath) { return (T) compile(jsonPath).read(json); } @@ -206,11 +271,51 @@ public class JsonPath { * * @param json a json object * @param jsonPath the json path - * @param + * @param expected return type * @return list of objects matched by the given path */ + @SuppressWarnings({"unchecked"}) public static T read(Object json, String jsonPath) { return (T) compile(jsonPath).read(json); } + /** + * Creates a new JsonPath and applies it to the provided Json object + * + * @param jsonURL url pointing to json doc + * @param jsonPath the json path + * @param expected return type + * @return list of objects matched by the given path + */ + @SuppressWarnings({"unchecked"}) + public static T read(URL jsonURL, String jsonPath) throws IOException { + return (T) compile(jsonPath).read(jsonURL); + } + + /** + * Creates a new JsonPath and applies it to the provided Json object + * + * @param jsonFile json file + * @param jsonPath the json path + * @param expected return type + * @return list of objects matched by the given path + */ + @SuppressWarnings({"unchecked"}) + public static T read(File jsonFile, String jsonPath) throws IOException { + return (T) compile(jsonPath).read(jsonFile); + } + + /** + * Creates a new JsonPath and applies it to the provided Json object + * + * @param jsonInputStream json input stream + * @param jsonPath the json path + * @param expected return type + * @return list of objects matched by the given path + */ + @SuppressWarnings({"unchecked"}) + public static T read(InputStream jsonInputStream, String jsonPath) throws IOException { + return (T) compile(jsonPath).read(jsonInputStream); + } + } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/PathToken.java new file mode 100644 index 00000000..48edae04 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/PathToken.java @@ -0,0 +1,43 @@ +/* + * 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.internal; + +import com.jayway.jsonpath.internal.filter.Filter; +import com.jayway.jsonpath.internal.filter.FilterFactory; +import com.jayway.jsonpath.spi.JsonProvider; + +/** + * @author Kalle Stenflo + */ +public class PathToken { + + private String fragment; + + public PathToken(String fragment) { + this.fragment = fragment; + } + + public Filter getFilter(){ + return FilterFactory.createFilter(fragment); + } + + public Object filter(Object model, JsonProvider jsonProvider){ + return FilterFactory.createFilter(fragment).filter(model, jsonProvider); + } + + public String getFragment() { + return fragment; + } +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java b/json-path/src/main/java/com/jayway/jsonpath/internal/PathTokenizer.java similarity index 88% rename from json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/PathTokenizer.java index eb5ee88e..efe0c7d1 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/PathTokenizer.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/PathTokenizer.java @@ -1,17 +1,27 @@ -package com.jayway.jsonpath.reader; +/* + * 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.internal; import com.jayway.jsonpath.InvalidPathException; -import com.jayway.jsonpath.spi.JsonProvider; import java.util.Iterator; import java.util.LinkedList; import java.util.List; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 9:53 PM + * @author Kalle Stenflo */ public class PathTokenizer implements Iterable { @@ -20,7 +30,7 @@ public class PathTokenizer implements Iterable { private int index = 0; private List pathTokens = new LinkedList(); - public PathTokenizer(String jsonPath, JsonProvider jsonProvider) { + public PathTokenizer(String jsonPath) { if (!jsonPath.startsWith("$") && !jsonPath.startsWith("$[")) { jsonPath = "$." + jsonPath; @@ -111,7 +121,6 @@ public class PathTokenizer implements Iterable { StringBuilder sb = new StringBuilder(); while (!isEmpty() && (!isStopChar(peek(), stopChars))) { - if (peek() == '(') { do { sb.append(poll()); diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayEvalFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilter.java similarity index 78% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayEvalFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilter.java index 39ce8ea7..15c3297b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayEvalFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayEvalFilter.java @@ -1,7 +1,21 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.InvalidPathException; -import com.jayway.jsonpath.reader.filter.eval.ExpressionEvaluator; +import com.jayway.jsonpath.internal.filter.eval.ExpressionEvaluator; import com.jayway.jsonpath.spi.JsonProvider; import java.util.List; @@ -10,14 +24,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/5/11 - * Time: 12:35 AM + * @author Kalle Stenflo */ public class ArrayEvalFilter extends Filter { - public static final Pattern PATTERN = Pattern.compile("(.*?)\\s?([=<>]+)\\s?(.*)"); + private static final Pattern PATTERN = Pattern.compile("(.*?)\\s?([=<>]+)\\s?(.*)"); public ArrayEvalFilter(String condition) { super(condition); diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayIndexFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayIndexFilter.java similarity index 71% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayIndexFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayIndexFilter.java index 840a731a..49039c1b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ArrayIndexFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ArrayIndexFilter.java @@ -1,14 +1,25 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.spi.JsonProvider; import java.util.List; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 11:25 PM + * @author Kalle Stenflo */ public class ArrayIndexFilter extends Filter { public ArrayIndexFilter(String condition) { diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/FieldFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java similarity index 77% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/FieldFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java index 82f940c3..623d44c0 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/FieldFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FieldFilter.java @@ -1,4 +1,18 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.spi.JsonProvider; @@ -6,10 +20,7 @@ import java.util.List; import java.util.Map; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 10:17 PM + * @author Kalle Stenflo */ public class FieldFilter extends Filter { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/Filter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/Filter.java new file mode 100644 index 00000000..2b6d5f5e --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/Filter.java @@ -0,0 +1,53 @@ +/* + * 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.internal.filter; + +import com.jayway.jsonpath.spi.JsonProvider; + +/** + * @author Kalle Stenflo + */ +public abstract class Filter { + + final String condition; + + Filter(String condition) { + this.condition = condition; + } + + + String trim(String str, int front, int end) { + String res = str; + + if (front > 0) { + res = str.substring(front); + } + if (end > 0) { + res = res.substring(0, res.length() - end); + } + return res; + } + + public Object filter(Object obj, JsonProvider jsonProvider, boolean inArrayContext){ + return filter(obj, jsonProvider); + } + + public abstract Object filter(Object obj, JsonProvider jsonProvider); + + + + public abstract boolean isArrayFilter(); + +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/FilterFactory.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterFactory.java similarity index 70% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/FilterFactory.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterFactory.java index 60070b78..7ca88bc1 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/FilterFactory.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterFactory.java @@ -1,10 +1,21 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 10:13 PM + * @author Kalle Stenflo */ public class FilterFactory { diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/HasFieldFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/HasFieldFilter.java similarity index 62% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/HasFieldFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/HasFieldFilter.java index 52e448f8..bccf223f 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/HasFieldFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/HasFieldFilter.java @@ -1,4 +1,18 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.spi.JsonProvider; @@ -6,10 +20,7 @@ import java.util.List; import java.util.Map; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/5/11 - * Time: 12:17 AM + * @author Kalle Stenflo */ public class HasFieldFilter extends Filter { diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/filter/PassthroughFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/PassthroughFilter.java new file mode 100644 index 00000000..1881081e --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/PassthroughFilter.java @@ -0,0 +1,40 @@ +/* + * 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.internal.filter; + +import com.jayway.jsonpath.spi.JsonProvider; + +/** + * @author Kalle Stenflo + */ +public class PassthroughFilter extends Filter { + + + private boolean isArrayFilter; + + public PassthroughFilter(String condition, boolean isArrayFilter) { + super(condition); + this.isArrayFilter = isArrayFilter; + } + + public Object filter(Object obj, JsonProvider jsonProvider) { + return obj; + } + + @Override + public boolean isArrayFilter() { + return isArrayFilter; + } +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ScanFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ScanFilter.java similarity index 62% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/ScanFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/ScanFilter.java index 49ae50ea..37472be6 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/ScanFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ScanFilter.java @@ -1,4 +1,18 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.spi.JsonProvider; @@ -6,10 +20,7 @@ import com.jayway.jsonpath.spi.JsonProvider; import java.util.List; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/7/11 - * Time: 12:31 PM + * @author Kalle Stenflo */ public class ScanFilter extends Filter { diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/WildcardFilter.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/WildcardFilter.java similarity index 55% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/WildcardFilter.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/WildcardFilter.java index 04177710..3034ab9d 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/WildcardFilter.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/WildcardFilter.java @@ -1,14 +1,25 @@ -package com.jayway.jsonpath.reader.filter; +/* + * 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.internal.filter; import com.jayway.jsonpath.spi.JsonProvider; import java.util.List; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/7/11 - * Time: 1:59 PM + * @author Kalle Stenflo */ public class WildcardFilter extends Filter { diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/eval/ExpressionEvaluator.java b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/eval/ExpressionEvaluator.java similarity index 82% rename from json-path/src/main/java/com/jayway/jsonpath/reader/filter/eval/ExpressionEvaluator.java rename to json-path/src/main/java/com/jayway/jsonpath/internal/filter/eval/ExpressionEvaluator.java index 82aac5a1..91928bcc 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/eval/ExpressionEvaluator.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/filter/eval/ExpressionEvaluator.java @@ -1,13 +1,24 @@ -package com.jayway.jsonpath.reader.filter.eval; +/* + * 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.internal.filter.eval; /** - * User: kalle stenflo - * Date: 2/4/11 - * Time: 9:21 PM + * @author Kalle Stenflo */ public class ExpressionEvaluator { - public static boolean eval(T actual, String comparator, String expected) { comparator = comparator.trim(); diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/reader/PathToken.java deleted file mode 100644 index cdacd552..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/PathToken.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.jayway.jsonpath.reader; - -import com.jayway.jsonpath.reader.filter.Filter; -import com.jayway.jsonpath.reader.filter.FilterFactory; -import com.jayway.jsonpath.spi.JsonProvider; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 10:00 PM - */ -public class PathToken { - - private String fragment; - - public PathToken(String fragment) { - this.fragment = fragment; - } - - public Filter getFilter(){ - return FilterFactory.createFilter(fragment); - } - - public Object filter(Object model, JsonProvider jsonProvider){ - return FilterFactory.createFilter(fragment).filter(model, jsonProvider); - } - - public String getFragment() { - return fragment; - } -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/Filter.java b/json-path/src/main/java/com/jayway/jsonpath/reader/filter/Filter.java deleted file mode 100644 index 72bbf99e..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/Filter.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.jayway.jsonpath.reader.filter; - -import com.jayway.jsonpath.spi.JsonProvider; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 10:14 PM - */ -public abstract class Filter { - - protected final String condition; - - public Filter(String condition) { - this.condition = condition; - } - - - protected String trim(String str, int front, int end) { - String res = str; - - if (front > 0) { - res = str.substring(front); - } - if (end > 0) { - res = res.substring(0, res.length() - end); - } - return res; - } - - public Object filter(Object obj, JsonProvider jsonProvider, boolean inArrayContext){ - return filter(obj, jsonProvider); - } - - public abstract Object filter(Object obj, JsonProvider jsonProvider); - - - - public abstract boolean isArrayFilter(); - -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/PassthroughFilter.java b/json-path/src/main/java/com/jayway/jsonpath/reader/filter/PassthroughFilter.java deleted file mode 100644 index 14020874..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/reader/filter/PassthroughFilter.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.jayway.jsonpath.reader.filter; - -import com.jayway.jsonpath.spi.JsonProvider; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/4/11 - * Time: 10:15 PM - */ -public class PassthroughFilter extends Filter { - - - private boolean isArrayFilter; - - public PassthroughFilter(String condition, boolean isArrayFilter) { - super(condition); - this.isArrayFilter = isArrayFilter; - } - - public Object filter(Object obj, JsonProvider jsonProvider) { - return obj; - } - - @Override - public boolean isArrayFilter() { - return isArrayFilter; - } -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProvider.java index cc95eb42..b3d674aa 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProvider.java @@ -1,34 +1,45 @@ +/* + * 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; import com.jayway.jsonpath.InvalidJsonException; -import com.jayway.jsonpath.spi.impl.JacksonProvider; -import com.jayway.jsonpath.spi.impl.JsonSmartProvider; +import java.io.InputStream; +import java.io.Reader; import java.util.List; import java.util.Map; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 3:51 PM + * @author Kalle Stenflo */ -public abstract class JsonProvider { +public interface JsonProvider { + + Mode getMode(); + + Object parse(String json) throws InvalidJsonException; - public abstract Mode getMode(); + Object parse(Reader jsonReader) throws InvalidJsonException; - public abstract Object parse(String json) throws InvalidJsonException; + Object parse(InputStream jsonStream) throws InvalidJsonException; - public abstract String toJson(Object obj); + String toJson(Object obj); - public abstract Map createMap(); + Map createMap(); - public abstract List createList(); + List createList(); - public static JsonProvider getInstance(){ - return new JsonSmartProvider(); - //return new JacksonProvider(); - } /** * checks if object is instanceof java.util.List or java.util.Map @@ -36,9 +47,7 @@ public abstract class JsonProvider { * @param obj object to check * @return true if List or Map */ - public boolean isContainer(Object obj) { - return (isList(obj) || isMap(obj)); - } + boolean isContainer(Object obj); /** * checks if object is instanceof java.util.List @@ -46,9 +55,7 @@ public abstract class JsonProvider { * @param obj object to check * @return true if List */ - public boolean isList(Object obj) { - return (obj instanceof List); - } + boolean isList(Object obj); /** * Converts give object to a List @@ -56,9 +63,7 @@ public abstract class JsonProvider { * @param list * @return */ - public List toList(Object list) { - return (List) list; - } + List toList(Object list); /** @@ -67,9 +72,7 @@ public abstract class JsonProvider { * @param map * @return */ - public Map toMap(Object map) { - return (Map) map; - } + Map toMap(Object map); /** * Extracts a value from a Map @@ -78,9 +81,7 @@ public abstract class JsonProvider { * @param key * @return */ - public Object getMapValue(Object map, String key) { - return toMap(map).get(key); - } + Object getMapValue(Object map, String key); /** * checks if object is instanceof java.util.Map @@ -88,9 +89,7 @@ public abstract class JsonProvider { * @param obj object to check * @return true if Map */ - public boolean isMap(Object obj) { - return (obj instanceof Map); - } + boolean isMap(Object obj); } diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java new file mode 100644 index 00000000..d94fe200 --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java @@ -0,0 +1,17 @@ +package com.jayway.jsonpath.spi; + +import com.jayway.jsonpath.spi.impl.JsonSmartProvider; + +/** + * Created by IntelliJ IDEA. + * User: kallestenflo + * Date: 3/2/12 + * Time: 9:45 PM + */ +public abstract class JsonProviderFactory { + + public static JsonProvider getInstance() { + return new JsonSmartProvider(); + } + +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/Mode.java b/json-path/src/main/java/com/jayway/jsonpath/spi/Mode.java index 5484675d..66aaca64 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/Mode.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/Mode.java @@ -1,12 +1,21 @@ +/* + * 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; - - /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 7:22 PM + * @author Kalle Stenflo */ public enum Mode { diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/impl/AbstractJsonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/AbstractJsonProvider.java new file mode 100644 index 00000000..37d023be --- /dev/null +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/AbstractJsonProvider.java @@ -0,0 +1,80 @@ +package com.jayway.jsonpath.spi.impl; + +import com.jayway.jsonpath.spi.JsonProvider; + +import java.util.List; +import java.util.Map; + +/** + * Created by IntelliJ IDEA. + * User: kallestenflo + * Date: 3/2/12 + * Time: 9:56 PM + */ +public abstract class AbstractJsonProvider implements JsonProvider { + + /** + * checks if object is instanceof java.util.List or java.util.Map + * + * @param obj object to check + * @return true if List or Map + */ + public boolean isContainer(Object obj) { + return (isList(obj) || isMap(obj)); + } + + /** + * checks if object is instanceof java.util.List + * + * @param obj object to check + * @return true if List + */ + public boolean isList(Object obj) { + return (obj instanceof List); + } + + /** + * Converts give object to a List + * + * @param list + * @return + */ + @SuppressWarnings({"unchecked"}) + public List toList(Object list) { + return (List) list; + } + + + /** + * Converts given object to a Map + * + * @param map + * @return + */ + @SuppressWarnings({"unchecked"}) + public Map toMap(Object map) { + return (Map) map; + } + + /** + * Extracts a value from a Map + * + * @param map + * @param key + * @return + */ + public Object getMapValue(Object map, String key) { + return toMap(map).get(key); + } + + /** + * checks if object is instanceof java.util.Map + * + * @param obj object to check + * @return true if Map + */ + public boolean isMap(Object obj) { + return (obj instanceof Map); + } + +} diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JacksonProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JacksonProvider.java index c3529ecd..3f6b9605 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JacksonProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JacksonProvider.java @@ -1,3 +1,17 @@ +/* + * 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.impl; import com.jayway.jsonpath.InvalidJsonException; @@ -6,18 +20,17 @@ import com.jayway.jsonpath.spi.Mode; import org.codehaus.jackson.map.ObjectMapper; import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 10:34 PM + * @author Kalle Stenflo */ -public class JacksonProvider extends JsonProvider { +public class JacksonProvider extends AbstractJsonProvider { @Override public Mode getMode() { return Mode.STRICT; @@ -32,6 +45,24 @@ public class JacksonProvider extends JsonProvider { } } + @Override + public Object parse(Reader jsonReader) throws InvalidJsonException { + try { + return new ObjectMapper().readValue(jsonReader, Object.class); + } catch (IOException e) { + throw new InvalidJsonException(e); + } + } + + @Override + public Object parse(InputStream jsonStream) throws InvalidJsonException { + try { + return new ObjectMapper().readValue(jsonStream, Object.class); + } catch (IOException e) { + throw new InvalidJsonException(e); + } + } + @Override public String toJson(Object obj) { throw new UnsupportedOperationException(); diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JsonSmartProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JsonSmartProvider.java index 3495f714..23e351a7 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JsonSmartProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/impl/JsonSmartProvider.java @@ -1,3 +1,17 @@ +/* + * 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.impl; import com.jayway.jsonpath.InvalidJsonException; @@ -9,16 +23,17 @@ import net.minidev.json.JSONObject; import net.minidev.json.parser.JSONParser; import net.minidev.json.parser.ParseException; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; import java.util.List; import java.util.Map; /** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/8/11 - * Time: 3:56 PM + * @author Kalle Stenflo */ -public class JsonSmartProvider extends JsonProvider { +public class JsonSmartProvider extends AbstractJsonProvider { private Mode mode; @@ -49,6 +64,24 @@ public class JsonSmartProvider extends JsonProvider { } } + @Override + public Object parse(Reader jsonReader) throws InvalidJsonException { + try { + return parser.parse(jsonReader); + } catch (ParseException e) { + throw new InvalidJsonException(e); + } + } + + @Override + public Object parse(InputStream jsonStream) throws InvalidJsonException { + try { + return parser.parse(new InputStreamReader(jsonStream)); + } catch (ParseException e) { + throw new InvalidJsonException(e); + } + } + @Override public String toJson(Object obj) { if(!(obj instanceof JSONAware)){ diff --git a/json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java b/json-path/src/test/java/com/jayway/jsonpath/ComplianceTest.java similarity index 98% rename from json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java rename to json-path/src/test/java/com/jayway/jsonpath/ComplianceTest.java index 64fbd224..53ec1ab0 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/ComplianceTests.java +++ b/json-path/src/test/java/com/jayway/jsonpath/ComplianceTest.java @@ -1,7 +1,5 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.reader.PathToken; -import com.jayway.jsonpath.reader.PathTokenizer; import org.hamcrest.Matchers; import org.junit.Test; @@ -15,7 +13,7 @@ import static org.junit.Assert.assertThat; /** * test defined in http://jsonpath.googlecode.com/svn/trunk/tests/jsonpath-test-js.html */ -public class ComplianceTests { +public class ComplianceTest { @Test public void test_one() throws Exception { @@ -82,6 +80,7 @@ public class ComplianceTests { //assertThat(JsonPath.>read(json, "$['points'][?(@.x * @.x + @.y * @.y > 50)].id"), hasItems(?)); //low } + @SuppressWarnings("UnusedAssignment") @Test public void test_four() throws Exception { String json = "{ \"menu\": {\n" + diff --git a/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java b/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java index 86cfdf8d..13c1a5b5 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java @@ -1,6 +1,6 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.reader.filter.eval.ExpressionEvaluator; +import com.jayway.jsonpath.internal.filter.eval.ExpressionEvaluator; import org.junit.Test; import static org.junit.Assert.assertFalse; @@ -14,12 +14,11 @@ import static org.junit.Assert.assertTrue; */ public class ExpressionEvalTest { - - @Test public void long_eval() throws Exception { assertTrue(ExpressionEvaluator.eval(1L, "=", "1")); + assertTrue(ExpressionEvaluator.eval(1L, "==", "1")); assertTrue(ExpressionEvaluator.eval(2L, "!=", "1")); assertTrue(ExpressionEvaluator.eval(2L, ">", "1")); assertTrue(ExpressionEvaluator.eval(2L, ">=", "1")); @@ -39,6 +38,7 @@ public class ExpressionEvalTest { public void double_eval() throws Exception { assertTrue(ExpressionEvaluator.eval(1D, "=", "1")); + assertTrue(ExpressionEvaluator.eval(1D, "==", "1")); assertTrue(ExpressionEvaluator.eval(2D, "!=", "1")); assertTrue(ExpressionEvaluator.eval(2D, ">", "1")); assertTrue(ExpressionEvaluator.eval(2D, ">=", "1")); @@ -57,7 +57,7 @@ public class ExpressionEvalTest { @Test public void string_eval() throws Exception { - assertTrue(ExpressionEvaluator.eval("A", "=", "A")); + assertTrue(ExpressionEvaluator.eval("A", "==", "A")); assertTrue(ExpressionEvaluator.eval("B", "!=", "A")); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/IsDefinitePathTest.java b/json-path/src/test/java/com/jayway/jsonpath/IsDefinitePathTest.java deleted file mode 100644 index 45ffd350..00000000 --- a/json-path/src/test/java/com/jayway/jsonpath/IsDefinitePathTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.jayway.jsonpath; - -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 2/3/11 - * Time: 9:58 PM - */ -public class IsDefinitePathTest { - - - @Test - public void path_is_not_definite() throws Exception { - assertFalse(JsonPath.compile("$..book[0]").isPathDefinite()); - assertFalse(JsonPath.compile("$.books[*]").isPathDefinite()); - } - - @Test - public void path_is_definite() throws Exception { - assertTrue(JsonPath.compile("$.definite.this.is").isPathDefinite()); - assertTrue(JsonPath.compile("rows[0].id").isPathDefinite()); - } - - -} diff --git a/json-path/src/test/java/com/jayway/jsonpath/IssueTests.java b/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java similarity index 95% rename from json-path/src/test/java/com/jayway/jsonpath/IssueTests.java rename to json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java index ed1f43c6..a2470acf 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/IssueTests.java +++ b/json-path/src/test/java/com/jayway/jsonpath/IssuesTest.java @@ -10,7 +10,7 @@ import static junit.framework.Assert.assertNull; * Date: 2/29/12 * Time: 8:42 AM */ -public class IssueTests { +public class IssuesTest { @Test public void issue_7() throws Exception { diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonModelMapperTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonModelMapperTest.java new file mode 100644 index 00000000..699eb5b1 --- /dev/null +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonModelMapperTest.java @@ -0,0 +1,148 @@ +package com.jayway.jsonpath; + +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; +import org.junit.Test; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; + +/** + * Created by IntelliJ IDEA. + * User: kallestenflo + * Date: 3/2/12 + * Time: 10:50 AM + */ +public class JsonModelMapperTest { + + public final static String DOCUMENT = + "{ \"store\": {\n" + + " \"book\": [ \n" + + " { \"category\": \"reference\",\n" + + " \"author\": \"Nigel Rees\",\n" + + " \"title\": \"Sayings of the Century\",\n" + + " \"displayPrice\": 8.95\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"Evelyn Waugh\",\n" + + " \"title\": \"Sword of Honour\",\n" + + " \"displayPrice\": 12.99\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"Herman Melville\",\n" + + " \"title\": \"Moby Dick\",\n" + + " \"isbn\": \"0-553-21311-3\",\n" + + " \"displayPrice\": 8.99\n" + + " },\n" + + " { \"category\": \"fiction\",\n" + + " \"author\": \"J. R. R. Tolkien\",\n" + + " \"title\": \"The Lord of the Rings\",\n" + + " \"isbn\": \"0-395-19395-8\",\n" + + " \"displayPrice\": 22.99\n" + + " }\n" + + " ],\n" + + " \"bicycle\": {\n" + + " \"color\": \"red\",\n" + + " \"displayPrice\": 19.95,\n" + + " \"foo:bar\": \"fooBar\",\n" + + " \"dot.notation\": \"new\",\n" + + " \"dash-notation\": \"dashes\"\n" + + " }\n" + + " }\n" + + "}"; + + + @Test + public void map_a_json_model() throws Exception { + + JsonModel model = JsonModel.create(DOCUMENT); + + List booksList = model.map("$.store.book[0,1]").toListOf(Book.class); + + Set bookSet = model.map("$.store.book[0,1]").toSetOf(Book.class); + + Book book = model.map("$.store.book[1]").to(Book.class); + + System.out.println("test"); + + } + + @Test + public void a_book_can_be_mapped() throws Exception { + + + //JsonPath.convert(DOCUMENT, "$.store.book[0,1]", List.class).to() + + //List books = JsonPath.read(DOCUMENT, "$.store.book[0,1]", List.class); + + ObjectMapper objectMapper = new ObjectMapper(); + + + /* + + +//Standard +List res = JsonPath.read(DOCUMENT, "$.store.book[0,1]"); +//or +List res = JsonPath.read(DOCUMENT, "$.store.book[0,1]", List.class); + + +//POJO Mapping med jackson ObjectMapper +List res = JsonPath.asList().of(Book.class).read(DOCUMENT, "$.store.book[0,1]"); + +List res = JsonPath.asListOf(Book.class).read(DOCUMENT, "$.store.book[0,1]"); + +Book res = JsonPath.as(Book.class).read(DOCUMENT, "$.store.book[0]"); + + */ + } + + public static class Book { + private String category; + private String author; + private String title; + private Double displayPrice; + + public Book() { + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Double getDisplayPrice() { + return displayPrice; + } + + public void setDisplayPrice(Double displayPrice) { + this.displayPrice = displayPrice; + } + } + +} + + + diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java index 3401b2f4..c493dda2 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonModelTest.java @@ -1,5 +1,7 @@ package com.jayway.jsonpath; +import com.jayway.jsonpath.spi.JsonProvider; +import com.jayway.jsonpath.spi.JsonProviderFactory; import com.jayway.jsonpath.util.ScriptEngineJsonPath; import org.junit.Test; @@ -57,7 +59,7 @@ public class JsonModelTest { Object result = model.get(path); - System.out.println(model.getJsonProvider().toJson(result)); + System.out.println(JsonProviderFactory.getInstance().toJson(result)); } @@ -99,7 +101,7 @@ public class JsonModelTest { JsonModel model = new JsonModel(DOCUMENT); - JsonModel model2 = model.getModel("store.book[0]"); + JsonModel model2 = model.getSubModel("store.book[0]"); System.out.println(model2.getJson()); diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonPathExtendedTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonPathExtendedTest.java deleted file mode 100644 index 5055bb66..00000000 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonPathExtendedTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.jayway.jsonpath; - -import org.junit.Test; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 11/12/11 - * Time: 8:25 PM - */ -public class JsonPathExtendedTest { - - public final static String DOCUMENT = - "{ \"store\": {\n" + - " \"book\": [ \n" + - " { \"category\": \"reference\",\n" + - " \"author\": \"Nigel Rees\",\n" + - " \"title\": \"Sayings of the Century\",\n" + - " \"price\": 8.95\n" + - " },\n" + - " { \"category\": \"fiction\",\n" + - " \"author\": \"Evelyn Waugh\",\n" + - " \"title\": \"Sword of Honour\",\n" + - " \"price\": 12.99\n" + - " },\n" + - " { \"category\": \"fiction\",\n" + - " \"author\": \"Herman Melville\",\n" + - " \"title\": \"Moby Dick\",\n" + - " \"isbn\": \"0-553-21311-3\",\n" + - " \"price\": 8.99\n" + - " },\n" + - " { \"category\": \"fiction\",\n" + - " \"author\": \"J. R. R. Tolkien\",\n" + - " \"title\": \"The Lord of the Rings\",\n" + - " \"isbn\": \"0-395-19395-8\",\n" + - " \"price\": 22.99\n" + - " }\n" + - " ],\n" + - " \"bicycle\": {\n" + - " \"color\": \"red\",\n" + - " \"price\": 19.95,\n" + - " \"foo:bar\": \"fooBar\",\n" + - " \"dot.notation\": \"new\"\n" + - " }\n" + - " }\n" + - "}"; - - - @Test - public void test_1() throws Exception { - - - JsonPath path = JsonPath.compile("$.store.book[*].title"); - - - - - } - -} diff --git a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java index 5ba9847d..75b1896d 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonPathTest.java @@ -1,6 +1,5 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.reader.PathTokenizer; import com.jayway.jsonpath.util.ScriptEngineJsonPath; import org.junit.Test; @@ -159,7 +158,6 @@ public class JsonPathTest { assertThat(JsonPath.>read(DOCUMENT, "$['store'].book[*]['author']"), hasItems("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien")); } - @Test public void all_authors() throws Exception { assertThat(JsonPath.>read(DOCUMENT, "$..author"), hasItems("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien")); @@ -264,9 +262,6 @@ public class JsonPathTest { } - @Test(expected = InvalidPathException.class) - public void invalid_new_path_throws_exception() throws Exception { - JsonPath.read(DOCUMENT, "new "); - } + } diff --git a/json-path/src/test/java/com/jayway/jsonpath/JacksonProviderTest.java b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java similarity index 98% rename from json-path/src/test/java/com/jayway/jsonpath/JacksonProviderTest.java rename to json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java index 349aba66..08d9e612 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/JacksonProviderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/JsonProviderTest.java @@ -9,7 +9,7 @@ import org.junit.Test; * Date: 11/8/11 * Time: 10:40 PM */ -public class JacksonProviderTest { +public class JsonProviderTest { public final static String ARRAY = "[{\"value\": 1},{\"value\": 2}, {\"value\": 3},{\"value\": 4}]"; diff --git a/json-path/src/test/java/com/jayway/jsonpath/ParserTest.java b/json-path/src/test/java/com/jayway/jsonpath/ParserTest.java deleted file mode 100644 index 3b606612..00000000 --- a/json-path/src/test/java/com/jayway/jsonpath/ParserTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.jayway.jsonpath; - -/** - * Created by IntelliJ IDEA. - * User: kallestenflo - * Date: 6/25/11 - * Time: 4:16 PM - */ -public class ParserTest { - - /* - private final static String SINGLE_QUOTE_JSON = "{'lhs': '1.0 U.S. dollar','rhs': 6.39778892, 'error': null, 'icc': true}"; - private final static String NO_QUOTE_JSON = "{lhs: 1.0 U.S. dollar, rhs: 6.39778892, error: null, icc: true}"; - - @Test - public void default_mode_is_SLACK_MODE() throws Exception { - assertEquals(JsonPath.SLACK_MODE, JsonPath.getMode()); - } - - @Test - public void slack_mode_allows_single_quotes() throws Exception { - assertEquals(JsonPath.read(SINGLE_QUOTE_JSON, "lhs"), "1.0 U.S. dollar"); - assertEquals(JsonPath.read(SINGLE_QUOTE_JSON, "rhs"), 6.39778892D); - } - - @Test - public void slack_mode_allows_no_quotes() throws Exception { - assertEquals(JsonPath.read(NO_QUOTE_JSON, "lhs"), "1.0 U.S. dollar"); - assertEquals(JsonPath.read(NO_QUOTE_JSON, "rhs"), 6.39778892D); - } - - @Test(expected = ParseException.class) - public void strict_mode_does_not_accept_single_quotes() throws Exception { - JsonPath.setMode(JsonPath.STRICT_MODE); - JsonPath.read(SINGLE_QUOTE_JSON, "lhs"); - } - - @Test(expected = ParseException.class) - public void strict_mode_does_not_accept_no_quotes() throws Exception { - JsonPath.setMode(JsonPath.STRICT_MODE); - JsonPath.read(NO_QUOTE_JSON, "lhs"); - } - */ - -} diff --git a/json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java b/json-path/src/test/java/com/jayway/jsonpath/PathTest.java similarity index 80% rename from json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java rename to json-path/src/test/java/com/jayway/jsonpath/PathTest.java index c7df6f7b..76b9fe4e 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/SplitPathFragmentsTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/PathTest.java @@ -1,11 +1,11 @@ package com.jayway.jsonpath; -import com.jayway.jsonpath.reader.PathTokenizer; -import com.jayway.jsonpath.spi.JsonProvider; +import com.jayway.jsonpath.internal.PathTokenizer; import org.hamcrest.Matcher; import org.junit.Test; import static org.hamcrest.Matchers.hasItems; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -15,32 +15,20 @@ import static org.junit.Assert.assertTrue; * Date: 2/2/11 * Time: 1:22 PM */ -public class SplitPathFragmentsTest { - - private JsonProvider jsonProvider = JsonProvider.getInstance(); - - +public class PathTest { @Test - public void array_filter_bracket_test() throws Exception { - - - PathTokenizer tokenizer = new PathTokenizer("$.store.book[?(@['isbn'])].isbn", jsonProvider); - //PathTokenizer tokenizer = new PathTokenizer("$.store.book[?(@.isbn)].isbn", jsonProvider); - - for (String fragment : tokenizer.getFragments()) { - System.out.println(fragment); - } - - //assertThat(tokenizer.getFragments(), hasItems("$", "store", "[*]")); - - - + public void path_is_not_definite() throws Exception { + assertFalse(JsonPath.compile("$..book[0]").isPathDefinite()); + assertFalse(JsonPath.compile("$.books[*]").isPathDefinite()); } - - + @Test + public void path_is_definite() throws Exception { + assertTrue(JsonPath.compile("$.definite.this.is").isPathDefinite()); + assertTrue(JsonPath.compile("rows[0].id").isPathDefinite()); + } @Test public void valid_path_is_split_correctly() throws Exception { @@ -122,7 +110,7 @@ public class SplitPathFragmentsTest { private void assertPathInvalid(String path) { try { - PathTokenizer tokenizer = new PathTokenizer(path, jsonProvider); + PathTokenizer tokenizer = new PathTokenizer(path); assertTrue("Expected exception!", false); } catch (InvalidPathException expected) {} } @@ -130,7 +118,7 @@ public class SplitPathFragmentsTest { private void assertPath(String path, Matcher> matcher) { System.out.println("PATH: " + path); - PathTokenizer tokenizer = new PathTokenizer(path, jsonProvider); + PathTokenizer tokenizer = new PathTokenizer(path); for (String fragment : tokenizer.getFragments()) { System.out.println(fragment); diff --git a/json-path/src/test/java/com/jayway/jsonpath/util/ScriptEngineJsonPath.java b/json-path/src/test/java/com/jayway/jsonpath/util/ScriptEngineJsonPath.java index 9118c64c..3d957eb2 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/util/ScriptEngineJsonPath.java +++ b/json-path/src/test/java/com/jayway/jsonpath/util/ScriptEngineJsonPath.java @@ -43,7 +43,6 @@ public class ScriptEngineJsonPath { private static String readScript(String script) { InputStream is = null; try { - is = ScriptEngineJsonPath.class.getClassLoader().getSystemResourceAsStream("js/" + script); return new Scanner(is).useDelimiter("\\A").next(); @@ -52,6 +51,7 @@ public class ScriptEngineJsonPath { try { is.close(); } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/pom.xml b/pom.xml index 0804797c..3362f880 100644 --- a/pom.xml +++ b/pom.xml @@ -86,8 +86,8 @@ maven-compiler-plugin 2.3.2 - 1.5 - 1.5 + 1.6 + 1.6 @@ -112,7 +112,34 @@ - + @@ -164,20 +191,15 @@ org.codehaus.jackson jackson-mapper-asl - 1.7.1 - - + org.hamcrest hamcrest-library 1.2.1 + org.hamcrest hamcrest-core @@ -190,6 +212,13 @@ 2.5 + + commons-io + commons-io + 2.1 + + + junit junit