Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:com.auditbucket.client.AbRestClient.java

/**
 * Converts the strings to a simple JSON representation
 *
 * @param headerRow - keys//from   ww w.j  a  v  a 2  s. c o m
 * @param line      - values
 * @return JSON Object
 * @throws JsonProcessingException
 */
public static String convertToJson(String[] headerRow, String[] line) throws JsonProcessingException {
    ObjectNode node = mapper.createObjectNode();
    for (int i = 0; i < headerRow.length; i++) {
        node.put(headerRow[i], line[i].trim());
    }
    return node.toString();
}

From source file:com.baasbox.service.storage.DocumentService.java

public static ODocument update(String collectionName, String rid, JsonNode bodyJson, PartsParser pp)
        throws MissingNodeException, InvalidCollectionException, InvalidModelException, ODatabaseException,
        IllegalArgumentException, DocumentNotFoundException {
    ODocument od = get(rid);//from w ww  . j av a  2  s.  co  m
    if (od == null)
        throw new InvalidParameterException(rid + " is not a valid document");
    ObjectMapper mapper = new ObjectMapper();
    StringBuffer q = new StringBuffer("");

    if (!pp.isMultiField() && !pp.isArray()) {
        q.append("update ").append(collectionName).append(" set ").append(pp.treeFields()).append(" = ")
                .append(bodyJson.get("data").toString());

    } else {
        q.append("update ").append(collectionName).append(" merge ");
        String content = od.toJSON();
        ObjectNode json = null;
        try {
            json = (ObjectNode) mapper.readTree(content.toString());
        } catch (Exception e) {
            throw new RuntimeException("Unable to modify inline json");
        }
        JsonTree.write(json, pp, bodyJson.get("data"));
        q.append(json.toString());
    }
    q.append(" where @rid = ").append(rid);
    try {
        DocumentDao.getInstance(collectionName).updateByQuery(q.toString());
    } catch (OSecurityException e) {
        throw e;
    } catch (InvalidCriteriaException e) {
        throw new RuntimeException(e);
    }
    od = get(collectionName, rid);
    return od;
}

From source file:controllers.Reconcile.java

/**
 * @param callback The name of the JSONP function to wrap the response in
 * @return OpenRefine reconciliation endpoint meta data, wrapped in `callback`
 *///from  w ww  .  ja va  2  s  . co  m
public static Result meta(String callback) {
    ObjectNode result = Json.newObject();
    result.put("name", "lobid-organisations reconciliation");
    result.put("identifierSpace", "http://beta.lobid.org/organisations");
    result.put("schemaSpace", "http://beta.lobid.org/organisations");
    result.put("defaultTypes", TYPES);
    result.put("view", Json.newObject()//
            .put("url", "http://beta.lobid.org/organisations/{{id}}"));
    return callback.isEmpty() ? ok(result)
            : ok(String.format("/**/%s(%s);", callback, result.toString())).as("application/json");
}

From source file:com.redhat.lightblue.query.RelationalExpression.java

/**
 * Parses a relational expression using the given object node
 *///from www .  j a va  2 s  .  co  m
public static RelationalExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("regex");
    if (x != null) {
        return RegexMatchExpression.fromJson(node);
    } else {
        x = node.get("op");
        if (x != null) {
            String op = x.asText();
            if (BinaryComparisonOperator.fromString(op) != null) {
                return BinaryRelationalExpression.fromJson(node);
            } else if (NaryRelationalOperator.fromString(op) != null) {
                return NaryRelationalExpression.fromJson(node);
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}

From source file:com.redhat.lightblue.query.RegexMatchExpression.java

public static RegexMatchExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("field");
    if (x != null) {
        Path field = new Path(x.asText());
        x = node.get("regex");
        if (x != null) {
            String regex = x.asText();
            return new RegexMatchExpression(field, regex, asBoolean(node.get("caseInsensitive")),
                    asBoolean(node.get("multiline")), asBoolean(node.get("extended")),
                    asBoolean(node.get("dotall")));
        }// www . j  a va2  s . co m
    }
    throw Error.get(QueryConstants.ERR_INVALID_REGEX_EXPRESSION, node.toString());
}

From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java

private static PatchMessage<DiffMatchPatchEdit> sendAddDoc(final String docId, final String clientId,
        final EmbeddedChannel ch) {
    final ObjectNode docMsg = message("add");
    docMsg.put("msgType", "add");
    docMsg.put("id", docId);
    docMsg.put("clientId", clientId);
    return fromJson(writeFrame(docMsg.toString(), ch), DiffMatchPatchMessage.class);
}

From source file:org.raegdan.troca.Main.java

private static void printRatesAsJSON(HashMap<String, Double> rates, boolean fancy) {
    JsonNodeFactory factory = new JsonNodeFactory(true);
    ObjectNode rootNode = new ObjectNode(factory);

    for (Entry<String, Double> rate : rates.entrySet())
        rootNode.put(rate.getKey(), rate.getValue());

    try {//from   w w w .j a v a  2s.  c  o m
        out((fancy) ? new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(rootNode)
                : rootNode.toString(), true);
    } catch (JsonProcessingException e) {
        printException(e);
    }
}

From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java

private static JsonNode sendAddDocMsg(final String docId, final String clientId, final String content,
        final EmbeddedChannel ch) {
    final ObjectNode docMsg = message("add");
    docMsg.put("msgType", "add");
    docMsg.put("id", docId);
    docMsg.put("clientId", clientId);
    docMsg.put("content", content);
    return writeTextFrame(docMsg.toString(), ch);
}

From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java

private static PatchMessage<DiffMatchPatchEdit> sendAddDoc(final String docId, final String clientId,
        final String content, final EmbeddedChannel ch) {
    final ObjectNode docMsg = message("add");
    docMsg.put("msgType", "add");
    docMsg.put("id", docId);
    docMsg.put("clientId", clientId);
    docMsg.put("content", content);
    return fromJson(writeFrame(docMsg.toString(), ch), DiffMatchPatchMessage.class);
}

From source file:com.redhat.lightblue.query.UnsetExpression.java

/**
 * Parses an unset expression using the given json object
 */// ww w .  j ava 2s. co  m
public static UnsetExpression fromJson(ObjectNode node) {
    if (node.size() == 1) {
        JsonNode val = node.get(UpdateOperator._unset.toString());
        if (val != null) {
            List<Path> fields = new ArrayList<>();
            if (val instanceof ArrayNode) {
                for (Iterator<JsonNode> itr = ((ArrayNode) val).elements(); itr.hasNext();) {
                    fields.add(new Path(itr.next().asText()));
                }
            } else if (val.isValueNode()) {
                fields.add(new Path(val.asText()));
            }
            return new UnsetExpression(fields);
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_UNSET_EXPRESSION, node.toString());
}