use of com.fasterxml.jackson.core.JsonParser in project opentsdb by OpenTSDB.
the class TestJSON method parseToStreamUTFSByte.
// parseToStream - Byte
@Test
public void parseToStreamUTFSByte() throws Exception {
JsonParser jp = JSON.parseToStream("{\"utf\":\"aƩriennes\",\"ascii\":\"aariennes\"}".getBytes("UTF8"));
HashMap<String, String> map = this.parseToMap(jp);
assertEquals("aƩriennes", map.get("utf"));
assertEquals("aariennes", map.get("ascii"));
}
use of com.fasterxml.jackson.core.JsonParser in project opentsdb by OpenTSDB.
the class TestJSON method parseToStreamASCIIByte.
@Test
public void parseToStreamASCIIByte() throws Exception {
JsonParser jp = JSON.parseToStream("{\"utf\":\"aeriennes\",\"ascii\":\"aariennes\"}".getBytes());
HashMap<String, String> map = this.parseToMap(jp);
assertEquals("aeriennes", map.get("utf"));
assertEquals("aariennes", map.get("ascii"));
}
use of com.fasterxml.jackson.core.JsonParser in project opentsdb by OpenTSDB.
the class TestJSON method parseToMap.
/** Helper to parse an input stream into a map */
private HashMap<String, String> parseToMap(final InputStream is) throws Exception {
JsonParser jp = JSON.parseToStream(is);
HashMap<String, String> map = new HashMap<String, String>();
String field = "";
String value;
while (jp.nextToken() != null) {
if (jp.getCurrentToken() == JsonToken.FIELD_NAME && jp.getCurrentName() != null) {
field = jp.getCurrentName();
} else if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
value = jp.getText();
map.put(field, value);
}
}
return map;
}
use of com.fasterxml.jackson.core.JsonParser in project beam by apache.
the class TestPipeline method convertToArgs.
public static String[] convertToArgs(PipelineOptions options) {
try {
byte[] opts = MAPPER.writeValueAsBytes(options);
JsonParser jsonParser = MAPPER.getFactory().createParser(opts);
TreeNode node = jsonParser.readValueAsTree();
ObjectNode optsNode = (ObjectNode) node.get("options");
ArrayList<String> optArrayList = new ArrayList<>();
Iterator<Entry<String, JsonNode>> entries = optsNode.fields();
while (entries.hasNext()) {
Entry<String, JsonNode> entry = entries.next();
if (entry.getValue().isNull()) {
continue;
} else if (entry.getValue().isTextual()) {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue().asText());
} else {
optArrayList.add("--" + entry.getKey() + "=" + entry.getValue());
}
}
return optArrayList.toArray(new String[optArrayList.size()]);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of com.fasterxml.jackson.core.JsonParser in project CzechIdMng by bcvsolutions.
the class IdentityReportRenderer method render.
@Override
public InputStream render(RptReportDto report) {
try {
// read json stream
JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Report");
// header
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Id");
cell = row.createCell(1);
cell.setCellValue("Username");
cell = row.createCell(2);
cell.setCellValue("First name");
cell = row.createCell(3);
cell.setCellValue("Last name");
cell = row.createCell(4);
cell.setCellValue("Disabled");
int rowNum = 1;
// json is array of identities
if (jParser.nextToken() == JsonToken.START_ARRAY) {
// write single identity
while (jParser.nextToken() == JsonToken.START_OBJECT) {
IdmIdentityDto identity = getMapper().readValue(jParser, IdmIdentityDto.class);
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue(identity.getId().toString());
cell = row.createCell(1);
cell.setCellValue(identity.getUsername());
cell = row.createCell(2);
cell.setCellValue(identity.getFirstName());
cell = row.createCell(3);
cell.setCellValue(identity.getLastName());
cell = row.createCell(4);
cell.setCellValue(identity.isDisabled());
}
}
// close json stream
jParser.close();
// close and return input stream
return getInputStream(workbook);
} catch (IOException ex) {
throw new ReportRenderException(report.getName(), ex);
}
}
Aggregations