Search in sources :

Example 1 with JsonParser

use of org.codehaus.jackson.JsonParser 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 JsonParser

use of org.codehaus.jackson.JsonParser 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 JsonParser

use of org.codehaus.jackson.JsonParser 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 JsonParser

use of org.codehaus.jackson.JsonParser in project hive by apache.

the class JsonSerDe method deserialize.

/**
   * Takes JSON string in Text form, and has to return an object representation above
   * it that's readable by the corresponding object inspector.
   *
   * For this implementation, since we're using the jackson parser, we can construct
   * our own object implementation, and we use HCatRecord for it
   */
@Override
public Object deserialize(Writable blob) throws SerDeException {
    Text t = (Text) blob;
    JsonParser p;
    List<Object> r = new ArrayList<Object>(Collections.nCopies(columnNames.size(), null));
    try {
        p = jsonFactory.createJsonParser(new ByteArrayInputStream((t.getBytes())));
        if (p.nextToken() != JsonToken.START_OBJECT) {
            throw new IOException("Start token not found where expected");
        }
        JsonToken token;
        while (((token = p.nextToken()) != JsonToken.END_OBJECT) && (token != null)) {
            // iterate through each token, and create appropriate object here.
            populateRecord(r, token, p, schema);
        }
    } catch (JsonParseException e) {
        LOG.warn("Error [{}] parsing json text [{}].", e, t);
        LOG.debug(null, e);
        throw new SerDeException(e);
    } catch (IOException e) {
        LOG.warn("Error [{}] parsing json text [{}].", e, t);
        LOG.debug(null, e);
        throw new SerDeException(e);
    }
    return new DefaultHCatRecord(r);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) JsonToken(org.codehaus.jackson.JsonToken) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) JsonParser(org.codehaus.jackson.JsonParser)

Example 5 with JsonParser

use of org.codehaus.jackson.JsonParser 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)

Aggregations

JsonParser (org.codehaus.jackson.JsonParser)21 JsonFactory (org.codehaus.jackson.JsonFactory)13 IOException (java.io.IOException)6 JsonParseException (org.codehaus.jackson.JsonParseException)5 ArrayList (java.util.ArrayList)4 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 List (java.util.List)3 GwtTestException (com.googlecode.gwt.test.exceptions.GwtTestException)2 GwtTestJSONException (com.googlecode.gwt.test.exceptions.GwtTestJSONException)2 File (java.io.File)2 Map (java.util.Map)2 PlanJSONDumpGenerator (org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator)2 JsonNode (org.codehaus.jackson.JsonNode)2 JsonToken (org.codehaus.jackson.JsonToken)2 TypeReference (org.codehaus.jackson.type.TypeReference)2 Message (com.amazonaws.services.sqs.model.Message)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)1 HarRequest (edu.umass.cs.benchlab.har.HarRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1