Search in sources :

Example 1 with JsonFactory

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());
    }
}
Also used : PlanJSONDumpGenerator(org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator) DataSinkNode(org.apache.flink.optimizer.dag.DataSinkNode) JsonFactory(org.codehaus.jackson.JsonFactory) JsonParseException(org.codehaus.jackson.JsonParseException) JsonParseException(org.codehaus.jackson.JsonParseException) JsonParser(org.codehaus.jackson.JsonParser)

Example 2 with JsonFactory

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;
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) File(java.io.File) JsonParser(org.codehaus.jackson.JsonParser)

Example 3 with JsonFactory

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);
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonParser(org.codehaus.jackson.JsonParser)

Example 4 with JsonFactory

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);
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) JsonParser(org.codehaus.jackson.JsonParser)

Example 5 with JsonFactory

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);
}
Also used : HttpServerResponse(io.reactivex.netty.protocol.http.server.HttpServerResponse) Arrays(java.util.Arrays) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RxNetty(io.reactivex.netty.RxNetty) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) BackendResponse(perf.test.utils.BackendResponse) ServiceResponseBuilder(perf.test.utils.ServiceResponseBuilder) JsonFactory(org.codehaus.jackson.JsonFactory) Observable(rx.Observable) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) ByteBuf(io.netty.buffer.ByteBuf) LogLevel(io.netty.handler.logging.LogLevel) JsonParseException(perf.test.utils.JsonParseException) HttpServerRequest(io.reactivex.netty.protocol.http.server.HttpServerRequest) Map(java.util.Map) HttpClient(io.reactivex.netty.protocol.http.client.HttpClient) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) HttpClientRequest(io.reactivex.netty.protocol.http.client.HttpClientRequest) HttpClientBuilder(io.reactivex.netty.protocol.http.client.HttpClientBuilder) BackendResponse(perf.test.utils.BackendResponse) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Observable(rx.Observable) JsonParseException(perf.test.utils.JsonParseException)

Aggregations

JsonFactory (org.codehaus.jackson.JsonFactory)38 JsonGenerator (org.codehaus.jackson.JsonGenerator)16 JsonParser (org.codehaus.jackson.JsonParser)13 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5 GenericRecord (org.apache.avro.generic.GenericRecord)4 JsonNode (org.codehaus.jackson.JsonNode)4 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 BufferedWriter (java.io.BufferedWriter)2 DataOutputStream (java.io.DataOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2