Search in sources :

Example 6 with JsonNodeFactory

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BBox(com.graphhopper.util.shapes.BBox) StorableProperties(com.graphhopper.storage.StorableProperties) ArrayList(java.util.ArrayList) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 7 with JsonNodeFactory

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());
    }
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 8 with JsonNodeFactory

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());
    }
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 9 with JsonNodeFactory

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PersistenceException(javax.persistence.PersistenceException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 10 with JsonNodeFactory

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Aggregations

JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)10 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 StorableProperties (com.graphhopper.storage.StorableProperties)1 BBox (com.graphhopper.util.shapes.BBox)1 IOException (java.io.IOException)1 PersistenceException (javax.persistence.PersistenceException)1 FromOperation (org.springframework.sync.FromOperation)1 PatchOperation (org.springframework.sync.PatchOperation)1