Example usage for com.fasterxml.jackson.databind JsonNode toString

List of usage examples for com.fasterxml.jackson.databind JsonNode toString

Introduction

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

Prototype

public abstract String toString();

Source Link

Usage

From source file:com.redhat.lightblue.metadata.ldap.parser.LdapPropertyParserTest.java

@Test
public void testConvert_NoMappings() throws IOException, JSONException {
    LdapMetadata ldapMetadata = new LdapMetadata();

    JsonNode node = json("{}");

    new LdapPropertyParser<JsonNode>()
            .convert(MetadataUtil.createJSONMetadataParser(LdapConstant.BACKEND, null), node, ldapMetadata);

    JSONAssert.assertEquals("{}", node.toString(), true);
}

From source file:com.redhat.lightblue.metadata.types.BinaryType.java

@Override
public Object fromJson(JsonNode node) {
    if (node.isValueNode()) {
        try {/*from  ww w. ja va 2  s  . c  o m*/
            return node.binaryValue();
        } catch (Exception e) {
        }
    }
    throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString());
}

From source file:fr.gouv.vitam.cases.RedisAccess.java

/**
 * Set the JsonNode as Id in database/*from  ww w  .  j av a 2  s .  c o m*/
 * @param id
 * @param node
 * @param ttl time to live in seconds
 * @return True if OK
 */
public final boolean setToId(final String id, final JsonNode node, final int ttl) {
    if (jedis == null) {
        return true;
    }
    final String nid = createDigest(id);
    String value = node.toString();
    String status = jedis.set(nid, value);
    return (status != null && status.equalsIgnoreCase("ok"));
}

From source file:com.baidubce.services.moladb.model.transform.AttributeValueUnmarshaller.java

@Override
public AttributeValue unmarshall(JsonNode jsonObj) throws Exception {

    if (jsonObj.isNull()) {
        logger.error("Input json obj is null");
        throw new BceClientException("Input json obj is null");
    }/*  ww  w .  j  a v  a2s .c om*/
    if (!jsonObj.isObject() || 0 == jsonObj.size()) {
        logger.error("Input json node:" + jsonObj.toString() + " is not a object or size is 0");
        throw new BceClientException("Illegal json:" + jsonObj.toString() + " for AttributeValue");
    }

    AttributeValue value = new AttributeValue();
    Iterator<String> fieldNames = jsonObj.fieldNames();
    String type = fieldNames.next();
    String val = jsonObj.get(type).asText();
    value.setValue(type, val);
    return value;
}

From source file:io.wcm.caravan.pipeline.impl.JacksonFunctionsTest.java

@Test
public void testStringToObjectNode() {
    JsonNode result = JacksonFunctions.stringToObjectNode("{\"id\":123,\"name\":\"abc\"}");

    // match generated JSON from String with expected JSON as String
    assertEquals("{\"id\":123,\"name\":\"abc\"}", result.toString());
}

From source file:org.createnet.raptor.db.couchbase.CouchbaseConnection.java

@Override
public void set(String id, JsonNode data, int ttlDays) {

    JsonObject obj = JsonObject.fromJson(data.toString());

    int ttl = ttlDays;
    if (ttlDays > 0) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, ttlDays);
        ttl = (int) (c.getTime().getTime() / 1000);
    }//from   w  ww. j a v  a2 s .co  m

    JsonDocument doc = JsonDocument.create(id, ttl, obj);
    bucket.upsert(doc);
}

From source file:ext.sns.auth.AccessTokenResponse.java

/**
 * ?/*from  www .jav a  2 s  .  c o  m*/
 * 
 * @param key ?key
 * @return ?Map
 */
public String getResponseValue(String key) {
    if (resultType == 1) {
        @SuppressWarnings("unchecked")
        Map<String, String> resultMap = (Map<String, String>) resultObject;
        return resultMap.get(key);
    } else if (resultType == 2) {
        JsonNode resultJson = (JsonNode) resultObject;

        if (!resultJson.hasNonNull(key)) {
            return null;
        }

        JsonNode valueNode = resultJson.get(key);
        if (valueNode.isContainerNode()) {
            return valueNode.toString();
        } else {
            return valueNode.asText();
        }

    } else {
        return null;
    }
}

From source file:com.infinities.keystone4j.admin.v3.group.GroupResourceTest.java

@Test
public void testGetGroup() throws JsonProcessingException, IOException {
    Response response = target("/v3/groups").path(group.getId()).register(JacksonFeature.class)
            .register(ObjectMapperResolver.class).request()
            .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get();
    assertEquals(200, response.getStatus());
    JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class));
    System.err.println(node.toString());
    JsonNode groupJ = node.get("group");
    assertEquals(group.getId(), groupJ.get("id").asText());
    assertEquals(group.getName(), groupJ.get("name").asText());
    assertEquals(group.getDomain().getId(), groupJ.get("domain_id").asText());
    assertEquals(group.getDescription(), groupJ.get("description").asText());
    assertNotNull(groupJ.get("links"));
    assertNotNull(groupJ.get("links").get("self").asText());
}

From source file:com.infinities.keystone4j.admin.v3.domain.DomainResourceTest.java

@Test
public void testUpdateDomain() throws ClientProtocolException, IOException {
    domain.setName("domain1");

    DomainWrapper wrapper = new DomainWrapper(domain);
    PatchClient client = new PatchClient("http://localhost:9998/v3/domains/" + domain.getId());
    JsonNode node = client.connect(wrapper);
    System.err.println(node.toString());

    JsonNode domainJ = node.get("domain");
    assertEquals(domain.getId(), domainJ.get("id").asText());
    assertEquals(domain.getName(), domainJ.get("name").asText());
    assertEquals(domain.getDescription(), domainJ.get("description").asText());
}

From source file:com.infinities.keystone4j.admin.v3.user.UserV3ResourceTest.java

@Test
public void testUpdateUser() throws ClientProtocolException, IOException {
    String userid = this.user.getId();
    UpdateUserParam user = new UpdateUserParam();
    user.setDefaultProjectId(project.getId());
    user.setDescription("description");
    user.setName("testing");
    user.setPassword("password");
    user.setEnabled(false);/*from w  w  w .  j a  v  a 2 s.  com*/
    UpdateUserParamWrapper wrapper = new UpdateUserParamWrapper(user);
    String json = JsonUtils.toJson(wrapper, Views.Advance.class);
    System.err.println(json);

    PatchClient client = new PatchClient("http://localhost:9998/v3/users/" + userid);
    JsonNode node = client.connect(wrapper);
    System.err.println(node.toString());
    JsonNode userJ = node.get("user");
    assertEquals(userid, userJ.get("id").asText());
    assertEquals(user.getName(), userJ.get("name").asText());
    assertEquals(user.getDescription(), userJ.get("description").asText());
    assertEquals(this.user.getDomainId(), userJ.get("domain_id").asText());
    assertEquals(user.getDefaultProjectId(), userJ.get("default_project_id").asText());
    assertEquals(user.getEnabled().booleanValue(), userJ.get("enabled").asBoolean());
    assertNull(userJ.get("password"));
}