use of com.fasterxml.jackson.core.JsonFactory in project CFLint by cflint.
the class TestCFLintConfig method test2.
@Test
public void test2() throws IOException {
StringWriter writer = new StringWriter();
JsonFactory jsonF = new JsonFactory();
JsonGenerator jg = jsonF.createGenerator(writer);
jg.writeStartArray();
jg.writeEndArray();
jg.close();
writer.close();
System.out.println(writer);
}
use of com.fasterxml.jackson.core.JsonFactory in project pyramid by cheng-li.
the class Visualizer method getPositions.
private List<Integer> getPositions(Object docId, Object field, Object keywords, Object slop, Object in_order) throws IOException {
System.out.println(docId + " " + field + " " + keywords + " " + slop + " " + in_order);
final URL url = new URL("http://localhost:9200/ohsumed_20000/document/_search");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.addRequestProperty("Content-Type", "application/" + "POST");
final String clauses = getJsonString(newSpanTerm((String) keywords, (String) field));
final String body = "{\"explain\":\"false\"," + " \"query\":{" + " \"filtered\":{" + " \"query\":{" + " \"span_near\": {" + " \"clauses\":" + clauses + "," + " \"slop\":" + slop.toString() + "," + " \"in_order\":" + in_order.toString() + "," + " \"collect_payloads\": false}}," + " \"filter\":{\"ids\":{\"values\":[\"" + docId + "\"]}}}}," + " \"highlight\":{\"fields\":{\"" + field + "\":{}}}," + " \"size\":1}";
System.out.println(body);
conn.setRequestProperty("Content-Length", Integer.toString(body.length()));
conn.getOutputStream().write(body.getBytes("UTF-8"));
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
final StringBuilder result = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null; ) {
result.append(line);
}
final JsonFactory factory = new JsonFactory();
final ObjectMapper mapper = new ObjectMapper(factory);
final Map<String, Object> hits = mapper.readValue(result.toString(), new TypeReference<Map<String, Object>>() {
});
final List<Integer> positions = new ArrayList<>();
if (hits.get("hits") != null && ((Map<String, Object>) hits.get("hits")).containsKey("hits")) {
for (String hlField : ((Map<String, Object>) ((Map<String, Object>) ((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0)).get("highlight")).keySet()) {
final String text = (String) ((Map<String, Object>) (((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0).get("_source"))).get(hlField);
final List<String> highlights = (List<String>) ((Map<String, Object>) (((List<Map<String, Object>>) ((Map<String, Object>) hits.get("hits")).get("hits")).get(0).get("highlight"))).get(hlField);
for (String HL : highlights) {
String cleanHL = HL.replaceAll("<em>", "");
cleanHL = cleanHL.replaceAll("</em>", "");
int baseindex = text.indexOf(cleanHL);
// in case the highlight not found in body
if (baseindex == -1) {
continue;
}
while (HL.indexOf("<em>") != -1) {
int start = HL.indexOf("<em>") + baseindex;
HL = HL.replace("<em>", "");
int end = HL.indexOf("</em>") + baseindex;
HL = HL.replace("</em>", "");
positions.add(start);
positions.add(end);
}
}
}
}
return positions;
}
use of com.fasterxml.jackson.core.JsonFactory in project pyramid by cheng-li.
the class Visualizer method loadJson.
private <T> T loadJson(File file, TypeReference<T> typeRef) throws IOException {
final JsonFactory factory = new JsonFactory();
final ObjectMapper mapper = new ObjectMapper(factory);
return mapper.readValue(file, typeRef);
}
use of com.fasterxml.jackson.core.JsonFactory in project drill by apache.
the class Metadata method writeFile.
/**
* Serialize parquet metadata to json and write to a file
*
* @param parquetTableMetadata
* @param p
* @throws IOException
*/
private void writeFile(ParquetTableMetadata_v3 parquetTableMetadata, Path p) throws IOException {
JsonFactory jsonFactory = new JsonFactory();
jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
ObjectMapper mapper = new ObjectMapper(jsonFactory);
SimpleModule module = new SimpleModule();
module.addSerializer(ColumnMetadata_v3.class, new ColumnMetadata_v3.Serializer());
mapper.registerModule(module);
FSDataOutputStream os = fs.create(p);
mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetTableMetadata);
os.flush();
os.close();
}
use of com.fasterxml.jackson.core.JsonFactory in project geode by apache.
the class PdxToJSON method getJSON.
public String getJSON() {
JsonFactory jf = new JsonFactory();
// OutputStream os = new ByteArrayOutputStream();
HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
enableDisableJSONGeneratorFeature(jg);
getJSONString(jg, m_pdxInstance);
jg.close();
return new String(hdos.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
hdos.close();
}
}
Aggregations