use of org.codehaus.jackson.JsonFactory in project OpenRefine by OpenRefine.
the class JsonImporter method createParserUIInitializationData.
@Override
public JSONObject createParserUIInitializationData(ImportingJob job, List<JSONObject> fileRecords, String format) {
JSONObject options = super.createParserUIInitializationData(job, fileRecords, format);
if (fileRecords.size() > 0) {
try {
JSONObject firstFileRecord = fileRecords.get(0);
File file = ImportingUtilities.getFile(job, firstFileRecord);
JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createJsonParser(file);
PreviewParsingState state = new PreviewParsingState();
Object rootValue = parseForPreview(parser, state);
if (rootValue != null) {
JSONUtilities.safePut(options, "dom", rootValue);
}
} catch (IOException e) {
logger.error("Error generating parser UI initialization data for JSON file", e);
}
}
return options;
}
use of org.codehaus.jackson.JsonFactory in project OpenRefine by OpenRefine.
the class Row method loadStreaming.
public static Row loadStreaming(String s, Pool pool) throws Exception {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jp = jsonFactory.createJsonParser(s);
if (jp.nextToken() != JsonToken.START_OBJECT) {
return null;
}
List<Cell> cells = new ArrayList<Cell>();
boolean starred = false;
boolean flagged = false;
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
jp.nextToken();
if (STARRED.equals(fieldName)) {
starred = jp.getBooleanValue();
} else if (FLAGGED.equals(fieldName)) {
flagged = jp.getBooleanValue();
} else if ("cells".equals(fieldName)) {
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
return null;
}
while (jp.nextToken() != JsonToken.END_ARRAY) {
Cell cell = Cell.loadStreaming(jp, pool);
cells.add(cell);
}
}
}
return (cells.size() > 0) ? new Row(cells, flagged, starred) : new Row(0);
}
use of org.codehaus.jackson.JsonFactory in project OpenRefine by OpenRefine.
the class Recon method loadStreaming.
public static Recon 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 OpenRefine by OpenRefine.
the class ReconCandidate method loadStreaming.
public static ReconCandidate loadStreaming(String s) throws Exception {
JsonFactory jsonFactory = new JsonFactory();
JsonParser jp = jsonFactory.createJsonParser(s);
if (jp.nextToken() != JsonToken.START_OBJECT) {
return null;
}
return loadStreaming(jp);
}
use of org.codehaus.jackson.JsonFactory in project jstorm by alibaba.
the class JSONUtil method formatPOJO2JSON.
/**
* POJO对象转换为JSON
* @param pojo
* @return
*/
public String formatPOJO2JSON(Object pojo) {
StringWriter stringWriter = new StringWriter();
String json = "";
try {
JsonGenerator gen = new JsonFactory().createJsonGenerator(stringWriter);
MAPPER.writeValue(gen, pojo);
gen.close();
json = stringWriter.toString();
} catch (Exception e) {
LOGGER.error(pojo.getClass().getName() + "转json出错", e);
}
return json;
}
Aggregations