Search in sources :

Example 1 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.

the class ObjectReaderTest method testNodeHandling.

public void testNodeHandling() throws Exception {
    JsonNodeFactory nodes = new JsonNodeFactory(true);
    ObjectReader r = MAPPER.reader().with(nodes);
    // but also no further changes if attempting again
    assertSame(r, r.with(nodes));
    assertTrue(r.createArrayNode().isArray());
    assertTrue(r.createObjectNode().isObject());
}
Also used : JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 2 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project jackson-databind by FasterXML.

the class ArrayNodeTest method testDirectCreation2.

public void testDirectCreation2() throws IOException {
    JsonNodeFactory f = objectMapper().getNodeFactory();
    ArrayList<JsonNode> list = new ArrayList<>();
    list.add(f.booleanNode(true));
    list.add(f.textNode("foo"));
    ArrayNode n = new ArrayNode(f, list);
    assertEquals(2, n.size());
    assertTrue(n.get(0).isBoolean());
    assertTrue(n.get(1).isTextual());
    // also, should fail with invalid set attempt
    try {
        n.set(2, f.nullNode());
        fail("Should not pass");
    } catch (IndexOutOfBoundsException e) {
        verifyException(e, "illegal index");
    }
    n.insert(1, (String) null);
    assertEquals(3, n.size());
    assertTrue(n.get(0).isBoolean());
    assertTrue(n.get(1).isNull());
    assertTrue(n.get(2).isTextual());
    n.removeAll();
    n.insert(0, (JsonNode) null);
    assertEquals(1, n.size());
    assertTrue(n.get(0).isNull());
}
Also used : ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 3 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project swagger-parser by swagger-api.

the class ResolverCacheTest method constructJsonTree.

private Pair<JsonNode, JsonNode> constructJsonTree(String... properties) {
    JsonNodeFactory factory = new JsonNodeFactory(true);
    final ObjectNode parent = factory.objectNode();
    ObjectNode current = parent;
    for (String property : properties) {
        current = current.putObject(property);
    }
    current.put("key", "value");
    return Pair.of((JsonNode) parent, (JsonNode) current);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 4 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 5 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project fabric8-maven-plugin by fabric8io.

the class HelmMojo method createTemplateParameters.

private void createTemplateParameters(File outputDir, Template template, File templatesDir) throws MojoExecutionException {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    ObjectNode values = nodeFactory.objectNode();
    List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
    if (parameters == null || parameters.isEmpty()) {
        return;
    }
    List<HelmParameter> helmParameters = new ArrayList<>();
    for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
        HelmParameter helmParameter = new HelmParameter(parameter);
        helmParameter.addToValue(values);
        helmParameters.add(helmParameter);
    }
    File outputChartFile = new File(outputDir, "values.yaml");
    try {
        saveYaml(values, outputChartFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to save chart values " + outputChartFile + ": " + e, e);
    }
    // now lets replace all the parameter expressions in each template
    File[] files = templatesDir.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.isFile()) {
                String extension = Files.getExtension(file.getName()).toLowerCase();
                if (extension.equals("yaml") || extension.equals("yml")) {
                    convertTemplateParameterExpressionsWithHelmExpressions(file, helmParameters);
                }
            }
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Parameter(org.apache.maven.plugins.annotations.Parameter) File(java.io.File)

Aggregations

JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)33 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)17 IOException (java.io.IOException)5 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)4 HashSet (java.util.HashSet)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 EventEntity (io.gravitee.management.model.EventEntity)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PersistenceException (javax.persistence.PersistenceException)2