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());
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations