use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project graphhopper by graphhopper.
the class InfoServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
BBox bb = storage.getBounds();
List<Double> list = new ArrayList<>(4);
list.add(bb.minLon);
list.add(bb.minLat);
list.add(bb.maxLon);
list.add(bb.maxLat);
final JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(false);
final ObjectNode json = jsonNodeFactory.objectNode();
json.putPOJO("bbox", list);
String[] vehicles = storage.getEncodingManager().toString().split(",");
json.putPOJO("supported_vehicles", vehicles);
ObjectNode features = json.putObject("features");
for (String v : vehicles) {
ObjectNode perVehicleJson = features.putObject(v);
perVehicleJson.put("elevation", hasElevation);
}
json.put("version", Constants.VERSION);
json.put("build_date", Constants.BUILD_DATE);
StorableProperties props = storage.getProperties();
json.put("import_date", props.get("datareader.import.date"));
if (!Helper.isEmpty(props.get("datareader.data.date")))
json.put("data_date", props.get("datareader.data.date"));
String tmpDate = props.get(Parameters.CH.PREPARE + "date");
if (!Helper.isEmpty(tmpDate)) {
json.put("prepare_ch_date", tmpDate);
json.put("prepare_date", tmpDate);
}
writeJson(req, res, json);
}
use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.
the class ArrayNodeTest method testNullAdds.
public void testNullAdds() {
JsonNodeFactory f = objectMapper().getNodeFactory();
ArrayNode array = f.arrayNode(14);
array.add((BigDecimal) null);
array.add((BigInteger) null);
array.add((Boolean) null);
array.add((byte[]) null);
array.add((Double) null);
array.add((Float) null);
array.add((Integer) null);
array.add((JsonNode) null);
array.add((Long) null);
array.add((String) null);
assertEquals(10, array.size());
for (JsonNode node : array) {
assertTrue(node.isNull());
}
}
use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.
the class ArrayNodeTest method testNullInserts.
public void testNullInserts() {
JsonNodeFactory f = objectMapper().getNodeFactory();
ArrayNode array = f.arrayNode(3);
array.insert(0, (BigDecimal) null);
array.insert(0, (BigInteger) null);
array.insert(0, (Boolean) null);
// Offsets out of the range are fine; negative become 0;
// super big just add at the end
array.insert(-56, (byte[]) null);
array.insert(0, (Double) null);
array.insert(200, (Float) null);
array.insert(0, (Integer) null);
array.insert(1, (JsonNode) null);
array.insert(array.size(), (Long) null);
array.insert(1, (String) null);
assertEquals(10, array.size());
for (JsonNode node : array) {
assertTrue(node.isNull());
}
}
use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project logging-log4j2 by apache.
the class ContextDataJsonAttributeConverter method convertToDatabaseColumn.
@Override
public String convertToDatabaseColumn(final ReadOnlyStringMap contextData) {
if (contextData == null) {
return null;
}
try {
final JsonNodeFactory factory = OBJECT_MAPPER.getNodeFactory();
final ObjectNode root = factory.objectNode();
contextData.forEach(new BiConsumer<String, Object>() {
@Override
public void accept(final String key, final Object value) {
// we will cheat here and write the toString of the Object... meh, but ok.
root.put(key, String.valueOf(value));
}
});
return OBJECT_MAPPER.writeValueAsString(root);
} catch (final Exception e) {
throw new PersistenceException("Failed to convert contextData to JSON string.", e);
}
}
use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class InfoArchiveRestClient method getValidJsonRequestForExport.
private String getValidJsonRequestForExport(String exportConfigurationUri, List<SearchResult> searchResults) {
JsonNodeFactory jsonNodeFactory = new ObjectMapper().getNodeFactory();
ObjectNode root = jsonNodeFactory.objectNode();
ArrayNode includedRows = jsonNodeFactory.arrayNode();
for (SearchResult searchResult : searchResults) {
for (Row row : searchResult.getRows()) {
includedRows.add(row.getId());
}
}
TextNode exportConfiguration = jsonNodeFactory.textNode(exportConfigurationUri);
root.set("exportConfiguration", exportConfiguration);
root.set("includedRows", includedRows);
return root.toString();
}
Aggregations