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:org.pentaho.metaverse.impl.model.kettle.json.TransMetaJsonDeserializer.java

protected void deserializeHops(TransMeta transMeta, JsonNode root, ObjectMapper mapper) {
    ArrayNode hopsArray = (ArrayNode) root.get(TransMetaJsonSerializer.JSON_PROPERTY_HOPS);
    for (int i = 0; i < hopsArray.size(); i++) {
        JsonNode hopNode = hopsArray.get(i);
        try {/* ww  w  . j  av  a  2  s  .  co m*/
            HopInfo hop = mapper.readValue(hopNode.toString(), HopInfo.class);
            if (hop != null) {
                TransHopMeta hopMeta = new TransHopMeta();
                hopMeta.setFromStep(transMeta.findStep(hop.getFromStepName()));
                hopMeta.setToStep(transMeta.findStep(hop.getToStepName()));
                hopMeta.setEnabled(hop.isEnabled());
                transMeta.addTransHop(hopMeta);
            }
        } catch (IOException e) {
            LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Hops"), e);
        }
    }
}

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

@Test
public void testListUserProjects() throws JsonProcessingException, IOException {
    final List<Project> projects = new ArrayList<Project>();
    projects.add(project);/*from   ww w.  j ava2s  .  com*/

    Response response = target("/v3/users").path(user.getId()).path("projects").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 projectsJ = node.get("projects");
    assertEquals(1, projectsJ.size());
    JsonNode projectJ = projectsJ.get(0);
    assertEquals(project.getId(), projectJ.get("id").asText());
    assertEquals(project.getName(), projectJ.get("name").asText());
    assertEquals(project.getDomain().getId(), projectJ.get("domain_id").asText());
}

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

@Test
public void testGetUser() throws JsonGenerationException, JsonMappingException, IOException {
    Response response = target("/v3/users").path(user.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 userJ = node.get("user");
    assertEquals(user.getId(), userJ.get("id").asText());
    assertEquals(user.getName(), userJ.get("name").asText());
    assertEquals(user.getDescription(), userJ.get("description").asText());
    assertEquals(user.getDomain().getId(), 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"));

}

From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDController_Objects_Test.java

@Test
public void test2PersonWithAddress_Find() throws Exception {
    Response response = lightblueFactory.getMediator().find(
            createRequest_FromResource(FindRequest.class, "./crud/find/person-with-address-find-single.json"));

    assertNotNull(response);//from w  w w .  ja  va 2 s  .  c o  m
    assertNoErrors(response);
    assertNoDataErrors(response);
    assertEquals(1, response.getMatchCount());

    JsonNode entityData = response.getEntityData();
    assertNotNull(entityData);
    JSONAssert.assertEquals(
            "[{\"dn\":\"uid=john.doe," + BASEDB_USERS
                    + "\",\"address\":{\"street\":\"123 Some St.\",\"postalCode\":12345,\"state\":\"NC\"}}]",
            entityData.toString(), true);
}

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

@Test
public void testListUsers() throws JsonProcessingException, IOException {
    final List<User> users = new ArrayList<User>();
    users.add(user);/*from   ww  w.ja  va 2s .co  m*/

    Response response = target("/v3/users").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 usersJ = node.get("users");
    assertEquals(2, usersJ.size());
    JsonNode userJ = usersJ.get(0);
    assertNotNull(userJ.get("id").asText());
    assertNotNull(userJ.get("name").asText());
    assertNotNull(userJ.get("description").asText());
    assertNotNull(userJ.get("domain_id").asText());
    assertNotNull(userJ.get("default_project_id").asText());
    assertNotNull(userJ.get("enabled").asText());
    assertNotNull(userJ.get("links"));
    assertNotNull(userJ.get("links").get("self").asText());
    assertNull(userJ.get("password"));
}

From source file:com.almende.eve.state.redis.RedisState.java

@Override
public JsonNode locPut(final String key, JsonNode value) {
    if (value == null) {
        value = NullNode.getInstance();//from w  w w  . j av  a2  s.  com
    }
    final Jedis redis = provider.getInstance();
    final String nkey = makeKey(key);
    redis.set(nkey, value.toString());
    redis.sadd(getId() + "_" + KEYS, nkey);
    provider.returnInstance(redis);
    return value;
}

From source file:org.createnet.raptor.models.objects.ServiceObject.java

/**
 * Merge an object representation to the current instance
 *
 * @param json the JsonNode object representation
 *//* www  .j ava 2s  .  c  o m*/
public void parse(JsonNode json) {
    parse(json.toString());
}

From source file:com.arpnetworking.configuration.jackson.akka.ActorRefSerializerTest.java

@Test
public void testSerializeDeserialize() throws IOException {
    final TestProbe probe = TestProbe.apply(getSystem());
    final JsonNode serialized = _mapper.valueToTree(probe.ref());

    final ActorSystem system2 = ActorSystem.create("Test");
    final ObjectMapper system2Mapper = ObjectMapperFactory.createInstance();
    system2Mapper.registerModule(new AkkaModule(system2));
    final ActorRef remoteRef = system2Mapper.readValue(serialized.toString(), ActorRef.class);

    remoteRef.tell("OK", ActorRef.noSender());
    probe.expectMsg(FiniteDuration.apply(3L, TimeUnit.SECONDS), "OK");
}

From source file:com.redhat.lightblue.crud.ldap.ITCaseLdapCRUDControllerTest.java

@Test
public void series1_phase2_Person_FindMany_WithPagination() throws Exception {
    Response response = getLightblueFactory().getMediator()
            .find(createRequest_FromResource(FindRequest.class, "./crud/find/person-find-many-paginated.json"));

    assertNotNull(response);/*  w w w  . j  a va 2  s . c  o m*/
    assertNoErrors(response);
    assertNoDataErrors(response);
    assertEquals(1, response.getMatchCount());

    JsonNode entityData = response.getEntityData();
    assertNotNull(entityData);

    JSONAssert.assertEquals("[{\"dn\":\"uid=john.doe," + BASEDB_USERS + "\"}]", entityData.toString(), true);
}

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

License:asdf

@Test
public void testFromJsonString() throws IOException {
    String jsonString = "{\"binaryData\": \"asdf\"}";

    JsonNode node = JsonUtils.json(jsonString);

    assertTrue(node != null);//  w w  w . j a  v  a  2 s. com

    JsonNode binaryDataNode = node.get("binaryData");

    assertTrue(binaryDataNode != null);
    byte[] bytes = binaryDataNode.binaryValue();
    assertTrue(bytes != null);
    assertTrue(bytes.length > 0);

    // try to convert back to json, verify we get the exact same thing
    JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    JsonNode binaryDataNodeOut = binaryType.toJson(jsonNodeFactory, bytes);

    assertTrue(binaryDataNodeOut != null);
    assertEquals("asdf", binaryDataNodeOut.asText());
    assertEquals("\"asdf\"", binaryDataNodeOut.toString());
}