use of org.codehaus.jackson.JsonFactory in project flink by apache.
the class PreviewPlanDumpTest method dump.
private void dump(Plan p) {
try {
List<DataSinkNode> sinks = Optimizer.createPreOptimizedPlan(p);
PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
String json = dumper.getPactPlanAsJSON(sinks);
JsonParser parser = new JsonFactory().createJsonParser(json);
while (parser.nextToken() != null) ;
} catch (JsonParseException e) {
e.printStackTrace();
Assert.fail("JSON Generator produced malformatted output: " + e.getMessage());
} catch (Exception e) {
e.printStackTrace();
Assert.fail("An error occurred in the test: " + e.getMessage());
}
}
use of org.codehaus.jackson.JsonFactory in project hive by apache.
the class JIRAService method parseJsonFile.
private static Map<String, Object> parseJsonFile(String jsonFile) throws IOException {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jsonParser = jsonFactory.createJsonParser(new File(jsonFile));
Map<String, Object> values = new HashMap<String, Object>();
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
if (supportedJsonFields.containsKey(fieldName)) {
jsonParser.nextToken();
Class clazz = supportedJsonFields.get(fieldName);
if (clazz == String.class) {
values.put(fieldName, jsonParser.getText());
} else if (clazz == Integer.class) {
values.put(fieldName, Integer.valueOf(jsonParser.getText()));
} else if (clazz == SortedSet.class) {
SortedSet<String> failedTests = new TreeSet<String>();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
failedTests.add(jsonParser.getText());
}
values.put(fieldName, failedTests);
} else if (clazz == List.class) {
List<String> messages = new ArrayList<String>();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
messages.add(jsonParser.getText());
}
values.put(fieldName, messages);
}
}
}
jsonParser.close();
return values;
}
use of org.codehaus.jackson.JsonFactory in project hive by apache.
the class JSONMessageFactory method getJsonTree.
public static ObjectNode getJsonTree(String eventMessage) throws Exception {
JsonParser jsonParser = (new JsonFactory()).createJsonParser(eventMessage);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(jsonParser, ObjectNode.class);
}
use of org.codehaus.jackson.JsonFactory in project OpenRefine by OpenRefine.
the class Cell method loadStreaming.
public static Cell loadStreaming(String s, Pool pool) throws Exception {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jp = jsonFactory.createJsonParser(s);
if (jp.nextToken() != JsonToken.START_OBJECT) {
return null;
}
return loadStreaming(jp, pool);
}
use of org.codehaus.jackson.JsonFactory in project WSPerfLab by Netflix-Skunkworks.
the class TestRouteBasic method handle.
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
long startTime = System.currentTimeMillis();
List<String> _id = request.getQueryParameters().get("id");
if (_id == null || _id.size() != 1) {
return writeError(request, response, "Please provide a numerical 'id' value. It can be a random number (uuid).");
}
long id = Long.parseLong(String.valueOf(_id.get(0)));
Observable<List<BackendResponse>> acd = getDataFromBackend("/mock.json?numItems=2&itemSize=50&delay=50&id=" + id).doOnError(Throwable::printStackTrace).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseA -> {
Observable<BackendResponse> responseC = getDataFromBackend("/mock.json?numItems=1&itemSize=5000&delay=80&id=" + responseA.getResponseKey());
Observable<BackendResponse> responseD = getDataFromBackend("/mock.json?numItems=1&itemSize=1000&delay=1&id=" + responseA.getResponseKey());
return Observable.zip(Observable.just(responseA), responseC, responseD, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
Observable<List<BackendResponse>> be = getDataFromBackend("/mock.json?numItems=25&itemSize=30&delay=150&id=" + id).<// Eclipse 20140224-0627 can't infer without this type hint even though the Java 8 compiler can
List<BackendResponse>>flatMap(responseB -> {
Observable<BackendResponse> responseE = getDataFromBackend("/mock.json?numItems=100&itemSize=30&delay=4&id=" + responseB.getResponseKey());
return Observable.zip(Observable.just(responseB), responseE, Arrays::asList);
}).doOnError(Throwable::printStackTrace);
return Observable.zip(acd, be, (_acd, _be) -> {
BackendResponse responseA = _acd.get(0);
BackendResponse responseB = _be.get(0);
BackendResponse responseC = _acd.get(1);
BackendResponse responseD = _acd.get(2);
BackendResponse responseE = _be.get(1);
return new BackendResponse[] { responseA, responseB, responseC, responseD, responseE };
}).flatMap(backendResponses -> {
try {
ByteArrayOutputStream responseStream = ServiceResponseBuilder.buildTestAResponse(jsonFactory, backendResponses);
response.getHeaders().addHeader("Content-Type", "application/json");
addResponseHeaders(response, startTime);
int contentLength = responseStream.size();
response.getHeaders().addHeader("Content-Length", contentLength);
return response.writeBytesAndFlush(responseStream.toByteArray());
} catch (Exception e) {
return writeError(request, response, "Failed: " + e.getMessage());
}
}).doOnError(Throwable::printStackTrace);
}
Aggregations