Browse Source

remove the get_json function that was accidentally introduced when merging #167 (fixes #180)

pull/195/head
Jochen Berger 9 years ago
parent
commit
a8bc2af229
  1. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java
  2. 49
      json-path/src/main/java/com/jayway/jsonpath/internal/function/http/HttpLoader.java
  3. 5
      json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

4
json-path/src/main/java/com/jayway/jsonpath/internal/function/PathFunctionFactory.java

@ -1,7 +1,6 @@
package com.jayway.jsonpath.internal.function;
import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.internal.function.http.HttpLoader;
import com.jayway.jsonpath.internal.function.json.Append;
import com.jayway.jsonpath.internal.function.numeric.Average;
import com.jayway.jsonpath.internal.function.numeric.Max;
@ -42,9 +41,6 @@ public class PathFunctionFactory {
// Text Functions
map.put("concat", Concatenate.class);
// Network functions
map.put("getjson", HttpLoader.class);
// JSON Entity Functions
map.put("length", Length.class);
map.put("size", Length.class);

49
json-path/src/main/java/com/jayway/jsonpath/internal/function/http/HttpLoader.java

@ -1,49 +0,0 @@
package com.jayway.jsonpath.internal.function.http;
import com.jayway.jsonpath.internal.EvaluationContext;
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.function.Parameter;
import com.jayway.jsonpath.internal.function.PathFunction;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.util.List;
/**
* Dirt simple http get method just to demo URL loading
*
* Created by mgreenwood on 12/11/15.
*/
public class HttpLoader implements PathFunction {
@Override
public Object invoke(String currentPath, PathRef parent, Object model, EvaluationContext ctx, List<Parameter> parameters) {
if (parameters != null && parameters.size() == 1) {
try {
URL url = new URL(parameters.get(0).getCachedValue().toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
StringBuffer result = new StringBuffer();
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
Object jsonResult = ctx.configuration().jsonProvider().parse(result.toString());
return jsonResult;
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}

5
json-path/src/test/java/com/jayway/jsonpath/internal/function/NestedFunctionTest.java

@ -68,11 +68,6 @@ public class NestedFunctionTest extends BaseFunctionTest {
verifyTextFunction(conf, "$.text.concat(\"-\", \"ghijk\")", "abcdef-ghijk");
}
@Test
public void testLoadFunction() {
verifyTextFunction(conf, "$.getjson($.urls[0])[0].total", 264);
}
@Test
public void testAppendNumber() {
verifyMathFunction(conf, "$.numbers.append(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 0).avg()", 10.0);

Loading…
Cancel
Save