Example usage for com.fasterxml.jackson.databind.node MissingNode getInstance

List of usage examples for com.fasterxml.jackson.databind.node MissingNode getInstance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node MissingNode getInstance.

Prototype

public static MissingNode getInstance() 

Source Link

Usage

From source file:com.github.fge.jackson.jsonpointer.JsonPointer.java

/**
 * Alternate constructor//from  www  .ja  v  a  2 s .com
 *
 * <p>This calls {@link TreePointer#TreePointer(TreeNode, List)} with a
 * {@link MissingNode} as the missing tree node.</p>
 *
 * @param tokenResolvers the list of token resolvers
 */
public JsonPointer(final List<TokenResolver<JsonNode>> tokenResolvers) {
    super(MissingNode.getInstance(), tokenResolvers);
}

From source file:com.squarespace.template.Context.java

public Context(JsonNode node, StringBuilder buf, Locale locale) {
    this.currentFrame = new Frame(null, node == null ? MissingNode.getInstance() : node);
    this.buf = buf == null ? new StringBuilder() : buf;
    this.locale = locale == null ? Locale.getDefault() : locale;
}

From source file:org.lendingclub.mercator.solarwinds.SolarwindsScanner.java

public void getNodeInformation() {
    try {//from  www. j  ava  2  s . c  om
        ObjectNode response = querySolarwinds("SELECT Nodes.NodeID, Nodes.SysName, Nodes.Caption, "
                + "Nodes.Description, Nodes.IOSVersion, Nodes.CustomProperties.SerialNumber, Nodes.MachineType, "
                + "Nodes.Vendor, Nodes.IPAddress, Nodes.SysObjectID, Nodes.DNS, Nodes.ObjectSubType, "
                + "Nodes.Status, Nodes.StatusDescription, Nodes.CustomProperties.Department, Nodes.Location,"
                + " Nodes.CustomProperties.City FROM Orion.Nodes ORDER BY Nodes.SysName");

        AtomicLong earlistUpdate = new AtomicLong(Long.MAX_VALUE);
        AtomicBoolean error = new AtomicBoolean(false);
        response.path("results").forEach(v -> {
            try {
                //solarwindsID is the hashedURL+nodeID
                getProjector().getNeoRxClient().execCypher(
                        "merge(a: SolarwindsNode {solarwindsID:{solarwindsID}}) set a+={props}, a.updateTs=timestamp() return a",
                        "solarwindsID", solarwindsScannerBuilder.hashURL + v.path("NodeID"), "props",
                        flattenNode(v)).blockingFirst(MissingNode.getInstance());
            } catch (Exception e) {
                logger.warn("problem", e);
                error.set(true);
            }

        });
        if (error.get() == false) {
            getNeoRxClient().execCypher(
                    "match(a: SolarwindsNode) where a.solarwindsID={solarwindsID} and  a.updateTs<{cutoff} detach delete a",
                    "solarwindsID", solarwindsScannerBuilder.hashURL, "cutoff", earlistUpdate.get());
        }
    } catch (Exception e) {
        logger.info(e.toString());
    }
}

From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java

/**
 * Parse the string into a Jackson Tree// w w  w. j  av  a  2  s.  com
 * <p>
 * Returns a missing node if the string is empty.
 *
 * @param jsonStr The Json string to parse.
 * @return The Jackson Json Tree
 * @throws IOException
 */
public static JsonNode parseJson(String jsonStr) throws IOException {
    if (StringUtils.isNullOrEmpty(jsonStr)) {
        return MissingNode.getInstance();
    }
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode root = objectMapper.readTree(jsonStr);
    if (null == root) {
        return MissingNode.getInstance();
    }
    return root;
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.api.AbstractApiControllerTest.java

@NotNull
protected Tuple2<Integer, JsonNode> fetchJson(final String rel, final boolean post) throws Exception {
    final JsonFactory factory = new JsonFactory();
    final HttpURLConnection conn = (HttpURLConnection) resolve(rel).toURL().openConnection();
    try {/*  w ww .ja v  a 2s.co  m*/
        conn.setRequestMethod(post ? "POST" : "GET");
        conn.setRequestProperty("Accept", "application/json");
        conn.connect();

        final int responseCode = conn.getResponseCode();

        InputStream in;
        try {
            in = conn.getInputStream();
        } catch (final IOException e) {
            in = conn.getErrorStream();
        }
        if (in == null) {
            return Tuple2.tuple2(responseCode, (JsonNode) MissingNode.getInstance());
        }

        assertEquals("application/json", conn.getHeaderField("Content-Type"));

        try {
            final ObjectMapper om = new ObjectMapper();
            return Tuple2.tuple2(responseCode, om.reader().with(factory).readTree(in));
        } finally {
            in.close();
        }
    } finally {
        conn.disconnect();
    }
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxCheckersTest.java

/**
 * Constructor/*from   w w w  .jav  a2 s .  c o m*/
 *
 * @param dict the {@link Dictionary} of {@link SyntaxChecker}s
 * @param prefix the prefix to use for resource files
 * @param keyword the keyword to test
 * @throws JsonProcessingException source JSON (if any) is not legal JSON
 */
protected SyntaxCheckersTest(final Dictionary<SyntaxChecker> dict, final String prefix, final String keyword)
        throws JsonProcessingException {
    this.keyword = keyword;
    checker = dict.entries().get(keyword);
    invalidTypes = checker == null ? null : EnumSet.complementOf(checker.getValidTypes());
    /*
     * Try and load the data and affect pointers. Barf on invalid JSON.
     *
     * If IOException, it means no file (hopefully); affect a MissingNode
     * to both valueTests and pointerTests.
     */
    JsonNode valueTestsNode, pointerTestsNode;
    try {
        final String resource = "/syntax/" + prefix + '/' + keyword + ".json";
        final JsonNode data = JsonLoader.fromResource(resource);
        valueTestsNode = data.path("valueTests");
        pointerTestsNode = data.path("pointerTests");
    } catch (JsonProcessingException oops) {
        throw oops;
    } catch (IOException ignored) {
        valueTestsNode = MissingNode.getInstance();
        pointerTestsNode = MissingNode.getInstance();
    }

    valueTests = valueTestsNode;
    pointerTests = pointerTestsNode;
}

From source file:org.eel.kitchen.jsonschema.ref.JsonPointer.java

@Override
public JsonNode resolve(final JsonNode node) {
    JsonNode ret = node;/*from w  w w .  j a  va 2s  .c o m*/

    for (final String pathElement : elements) {
        if (!ret.isContainerNode())
            return MissingNode.getInstance();
        if (ret.isObject())
            ret = ret.path(pathElement);
        else
            try {
                ret = ret.path(Integer.parseInt(pathElement));
            } catch (NumberFormatException ignored) {
                return MissingNode.getInstance();
            }
        if (ret.isMissingNode())
            break;
    }

    return ret;
}

From source file:org.lendingclub.mercator.docker.SwarmScanner.java

public void scan() {
    WebTarget t = extractWebTarget(dockerScanner.getDockerClient());
    logger.info("Scanning {}", t);
    JsonNode response = t.path("/info").request().buildGet().invoke(JsonNode.class);

    JsonNode swarm = response.path("Swarm");
    JsonNode cluster = swarm.path("Cluster");
    String swarmClusterId = cluster.path("ID").asText();

    // need to parse these dates
    String createdAt = cluster.path("CreatedAt").asText();
    String updatedAt = cluster.path("UpdatedAt").asText();
    ObjectNode props = mapper.createObjectNode();
    props.put("swarmClusterId", swarmClusterId);
    props.put("createdAt", createdAt);
    props.put("updatedAt", updatedAt);

    JsonNode swarmNode = dockerScanner.getNeoRxClient().execCypher(
            "merge (c:DockerSwarm {swarmClusterId:{id}}) set c+={props},c.updateTs=timestamp() return c", "id",
            swarmClusterId, "props", props).blockingFirst(MissingNode.getInstance());

    if (isUnixDomainScoket(t.getUri().toString())) {
        // Only set managerApiUrl to a unix domain socket if it has not
        // already been set.
        // This is useful for trident
        if (!isUnixDomainScoket(swarmNode.path("managerApiUrl").asText())) {

            String LOCAL_DOCKER_DAEMON_SOCKET_URL = "unix:///var/run/docker.sock";
            logger.info("setting mangerApiUrl to {} for swarm {}", LOCAL_DOCKER_DAEMON_SOCKET_URL,
                    swarmClusterId);/*from  www. j  a v  a 2  s  .  co  m*/

            String name = "local";
            dockerScanner.getNeoRxClient()
                    .execCypher("match (c:DockerSwarm {name:{name}}) return c", "name", name).forEach(it -> {
                        String oldSwarmClusterId = it.path("swarmClusterId").asText();
                        if (!swarmClusterId.equals(oldSwarmClusterId)) {
                            dockerScanner.getNeoRxClient().execCypher(
                                    "match (c:DockerSwarm {swarmClusterId:{swarmClusterId}}) detach delete c",
                                    "swarmClusterId", oldSwarmClusterId);
                        }
                    });

            dockerScanner.getNeoRxClient().execCypher(
                    "match (c:DockerSwarm {swarmClusterId:{id}}) set c.managerApiUrl={managerApiUrl},c.name={name},c.tridentClusterId={name} return c",
                    "id", swarmClusterId, "managerApiUrl", LOCAL_DOCKER_DAEMON_SOCKET_URL, "name", name);

        }
    }

    AtomicBoolean fail = new AtomicBoolean(false);
    response = t.path("/nodes").request().buildGet().invoke(JsonNode.class);
    AtomicLong earliestTimestamp = new AtomicLong(Long.MAX_VALUE);
    response.elements().forEachRemaining(it -> {
        try {
            earliestTimestamp.set(
                    Math.min(earliestTimestamp.get(), saveDockerNode(swarmClusterId, flattenSwarmNode(it))));
        } catch (RuntimeException e) {
            logger.warn("problem", e);
            fail.set(true);
        }
    });

    if (!fail.get()) {
        if (earliestTimestamp.get() < System.currentTimeMillis()) {
            logger.info("deleting DockerHost nodes before with updateTs<{}", earliestTimestamp.get());
            dockerScanner.getNeoRxClient().execCypher(
                    "match (s:DockerSwarm {swarmClusterId:{id}})--(x:DockerHost) where s.updateTs>x.updateTs detach delete x",
                    "id", swarmClusterId);
        }
    }
    scanServicesForSwarm(swarmClusterId);
    scanTasksForSwarm(swarmClusterId);
}

From source file:io.sidecar.event.EventJsonValidationTest.java

@Test(description = "Assert that the tags key is excluded if empty when deserializing")
public void serializationRemovesNullTags() throws Exception {
    eventAsObjectNode.remove("tags");
    Event e = mapper.readValue(eventAsObjectNode.traverse(), Event.class);

    JsonNode serialized = mapper.readTree(mapper.writeValueAsBytesUnchecked(e));
    JsonNode tagsPath = serialized.path("tags");
    assertTrue(MissingNode.getInstance().equals(tagsPath));
}

From source file:io.sidecar.event.EventJsonValidationTest.java

@Test(description = "Assert that the tags key is excluded if empty when deserializing")
public void serializationRemovesNullKeyTags() throws Exception {
    eventAsObjectNode.remove("keytags");
    Event e = mapper.readValue(eventAsObjectNode.traverse(), Event.class);

    JsonNode serialized = mapper.readTree(mapper.writeValueAsBytesUnchecked(e));
    JsonNode keyTagsPath = serialized.path("keytags");
    assertTrue(MissingNode.getInstance().equals(keyTagsPath));
}