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.redhat.lightblue.query.NaryFieldRelationalExpression.java

/**
 * Parses an n-ary relational expression from the given json object
 *///from w w w .j a v  a2 s.com
public static NaryFieldRelationalExpression fromJson(ObjectNode node) {
    if (node.size() == 3) {
        JsonNode x = node.get("op");
        if (x != null) {
            NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText());
            if (op != null) {
                x = node.get("field");
                if (x != null) {
                    Path field = new Path(x.asText());
                    x = node.get("rfield");
                    if (x != null) {
                        return new NaryFieldRelationalExpression(field, op, new Path(x.asText()));
                    }
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}

From source file:models.service.reminder.RemindService.java

/**
 * ???/*from  ww  w  .j a v  a2 s  . co m*/
 * 
 * @param session Http session
 * @param user ?
 * @param cfg Json
 * @param items ?items
 * 
 * @return true - ??, false - ?
 */
public static boolean saveCfgJson(Http.Session session, User user, JsonNode cfg, Item[] cfgItems) {
    boolean isValidCfg = verifyCfg(cfg, cfgItems);

    if (!isValidCfg) {
        return false;
    }

    JsonNode oldUserCfg = null;
    if (StringUtils.isNotBlank(user.safetyReminderConfig)) {
        oldUserCfg = Json.parse(user.safetyReminderConfig);
    }
    ObjectNode newUserCfg = Json.newObject();
    for (Item item : Item.values()) {
        String val = item.getVal();

        if (ArrayUtils.contains(cfgItems, item)) {
            newUserCfg.set(val, cfg.get(val));
        } else {
            if (null != oldUserCfg && oldUserCfg.hasNonNull(val)) {
                newUserCfg.set(val, oldUserCfg.get(val));
            }
        }
    }

    JPA.em().createQuery("update User set safetyReminderConfig=:newCfg where id=:id")
            .setParameter("newCfg", newUserCfg.toString()).setParameter("id", user.id).executeUpdate();

    LoginUserCache.refreshBySession(session);

    return true;
}

From source file:com.squarespace.template.plugins.CoreFormattersTest.java

protected static String getDateTestJson(long timestamp, String tzId) {
    DateTimeZone timezone = DateTimeZone.forID(tzId);
    ObjectNode node = JsonUtils.createObjectNode();
    node.put("time", timestamp);
    ObjectNode website = JsonUtils.createObjectNode();
    website.put("timeZoneOffset", timezone.getOffset(timestamp));
    website.put("timeZone", timezone.getID());
    node.put("website", website);
    return node.toString();
}

From source file:org.apache.streams.converter.TypeConverterUtil.java

public static Object convert(Object object, Class outClass, ObjectMapper mapper) {
    ObjectNode node = null;
    Object outDoc = null;// ww  w .j  ava  2  s  . c o  m
    if (object instanceof String) {
        try {
            node = mapper.readValue((String) object, ObjectNode.class);
        } catch (IOException e) {
            LOGGER.warn(e.getMessage());
            LOGGER.warn(object.toString());
        }
    } else {
        node = mapper.convertValue(object, ObjectNode.class);
    }

    if (node != null) {
        try {
            if (outClass == String.class)
                outDoc = mapper.writeValueAsString(node);
            else
                outDoc = mapper.convertValue(node, outClass);

        } catch (Throwable e) {
            LOGGER.warn(e.getMessage());
            LOGGER.warn(node.toString());
        }
    }

    return outDoc;
}

From source file:com.marklogic.client.functionaltest.JavaApiBatchSuite.java

public static void createRESTUser(String usrName, String pass, String roleName) {
    try {/*from  w w  w. j  a va 2  s. c o  m*/
        DefaultHttpClient client = new DefaultHttpClient();
        client.getCredentialsProvider().setCredentials(new AuthScope("localhost", 8002),
                new UsernamePasswordCredentials("admin", "admin"));
        HttpPost post = new HttpPost("http://localhost:8002" + "/manage/v2/users?format=json");
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode mainNode = mapper.createObjectNode();
        //         ObjectNode childNode = mapper.createObjectNode();
        ArrayNode childArray = mapper.createArrayNode();
        mainNode.put("name", usrName);
        mainNode.put("description", "user discription");
        mainNode.put("password", pass);
        childArray.add(roleName);
        mainNode.put("role", childArray);
        //System.out.println(type + mainNode.path("range-element-indexes").path("range-element-index").toString());
        //            System.out.println(mainNode.toString());
        post.addHeader("Content-type", "application/json");
        post.setEntity(new StringEntity(mainNode.toString()));

        HttpResponse response = client.execute(post);
        HttpEntity respEntity = response.getEntity();
        if (response.getStatusLine().getStatusCode() == 400) {
            System.out.println("User already exist or a bad create request");
        } else if (respEntity != null) {
            // EntityUtils to get the response content
            String content = EntityUtils.toString(respEntity);
            System.out.println(content);
        } else {
            System.out.print("No Proper Response");
        }
    } catch (Exception e) {
        // writing error to Log
        e.printStackTrace();
    }
}

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

/**
 * Parses an ArrayContainsExpression from a JSON object node.
 *//*from   w  w w . ja  v a 2  s.  c  o  m*/
public static ArrayContainsExpression fromJson(ObjectNode node) {
    JsonNode x = node.get("array");
    if (x != null) {
        Path field = new Path(x.asText());
        x = node.get("contains");
        if (x != null) {
            ContainsOperator op = ContainsOperator.fromString(x.asText());
            if (op != null) {
                x = node.get("values");
                if (x instanceof ArrayNode) {
                    ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size());
                    for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) {
                        values.add(Value.fromJson(itr.next()));
                    }
                    return new ArrayContainsExpression(field, op, values);
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString());
}

From source file:com.msopentech.odatajclient.testservice.utils.Commons.java

public static InputStream getLinksAsJSON(final String entitySetName,
        final Map.Entry<String, Collection<String>> link) throws IOException {
    final ObjectNode links = new ObjectNode(JsonNodeFactory.instance);
    links.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + entitySetName + "/$links/" + link.getKey());

    final ArrayNode uris = new ArrayNode(JsonNodeFactory.instance);

    for (String uri : link.getValue()) {
        final String absoluteURI;
        if (URI.create(uri).isAbsolute()) {
            absoluteURI = uri;/* www . j a v  a  2s .c om*/
        } else {
            absoluteURI = DEFAULT_SERVICE_URL + uri;
        }
        uris.add(new ObjectNode(JsonNodeFactory.instance).put("url", absoluteURI));
    }

    if (uris.size() == 1) {
        links.setAll((ObjectNode) uris.get(0));
    } else {
        links.set("value", uris);
    }

    return IOUtils.toInputStream(links.toString());
}

From source file:org.jpos.ee.converter.ObjectNodeConverter.java

@Override
public String convertToDatabaseColumn(ObjectNode attribute) {
    return attribute.toString();
}

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

/**
 * Parses a field comparison or value comparison expression from the given
 * json object//from  ww w .  j a  v a 2s .c  o  m
 */
public static BinaryRelationalExpression fromJson(ObjectNode node) {
    if (node.size() == 3) {
        JsonNode x = node.get("op");
        if (x != null) {
            BinaryComparisonOperator op = BinaryComparisonOperator.fromString(x.asText());
            if (op != null) {
                x = node.get("field");
                if (x != null) {
                    Path field = new Path(x.asText());
                    x = node.get("rfield");
                    if (x != null) {
                        return new FieldComparisonExpression(field, op, new Path(x.asText()));
                    } else {
                        x = node.get("rvalue");
                        if (x != null) {
                            return new ValueComparisonExpression(field, op, Value.fromJson(x));
                        }
                    }
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}

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

/**
 * Parses an n-ary relational expression from the given json object
 */// w w  w  .  j  av  a  2  s  .com
public static NaryValueRelationalExpression fromJson(ObjectNode node) {
    if (node.size() == 3) {
        JsonNode x = node.get("op");
        if (x != null) {
            NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText());
            if (op != null) {
                x = node.get("field");
                if (x != null) {
                    Path field = new Path(x.asText());
                    x = node.get("values");
                    if (x instanceof ArrayNode) {
                        ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size());
                        for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) {
                            values.add(Value.fromJson(itr.next()));
                        }
                        return new NaryValueRelationalExpression(field, op, values);
                    }
                }
            }
        }
    }
    throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString());
}