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.eval.ListProjectorTest.java

@Test
public void two_$parent_projection_list() throws Exception {
    String pr = "[{'field':'field7.$parent.field6.*','include':1},{'field':'field5'}]";
    Projector projector = projector(pr, md);
    JsonNode expectedNode = JsonUtils.json(
            "{'field5':true,'field6':{'nf1':'nvalue1','nf2':'nvalue2','nf3':4,'nf4':false,'nf5':[],'nf6':[],'nf7':{},'nf8':[],'nf9':[],'nf10':[],'nf11':null}}"
                    .replace('\'', '\"'));

    JsonDoc newDoc = projector.project(doc, factory);

    Assert.assertEquals(expectedNode.toString(), newDoc.toString());
}

From source file:com.ikanow.aleph2.distributed_services.services.TestCoreDistributedServices.java

@Test
public void testKafkaForStormSpout() throws Exception {
    if (!auto_configure) { // Only test this once per true/false cycle
        return;/*ww w .  j  ava2  s .co m*/
    }

    System.out.println("STARTING TEST: testKafkaForStormSpout");

    //create a topic for a kafka spout, put some things in the spout      
    final String TOPIC_NAME = "TEST_KAFKA_SPOUT_" + System.currentTimeMillis();
    final int num_to_test = 100; //set this high enough to hit the concurrent connection limit just incase we messed something up

    //grab the consumer      
    Iterator<String> consumer = _core_distributed_services.consumeAs(TOPIC_NAME, Optional.empty(),
            Optional.empty());

    //throw items on the queue      
    JsonNode jsonNode = new ObjectMapper()
            .readTree("{\"keyA\":\"val21\",\"keyB\":\"val22\",\"keyC\":\"val23\"}");
    String original_message = jsonNode.toString();
    for (int i = 0; i < num_to_test; i++)
        _core_distributed_services.produce(TOPIC_NAME, original_message);
    Thread.sleep(5000); //wait a few seconds for producers to dump batch

    String consumed_message = null;
    int message_count = 0;
    //read the item off the queue
    while (consumer.hasNext()) {
        consumed_message = consumer.next();
        message_count++;
        System.out.println(consumed_message);
    }

    _core_distributed_services.deleteTopic(TOPIC_NAME);

    assertEquals(message_count, num_to_test);
}

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

@Test
public void series2_phase2_Department_FindWithInsufficientRoles() throws Exception {
    FindRequest findRequest = createRequest_FromResource(FindRequest.class,
            "./crud/find/department-find-single.json");
    findRequest.setClientId(new FakeClientIdentification("fakeUser"));

    Response response = getLightblueFactory().getMediator().find(findRequest);

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

    assertNoErrors(response);
    assertNoDataErrors(response);

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

    JSONAssert.assertEquals("[{\"cn\":\"Marketing\",\"description\":\"Department devoted to Marketing\"}]",
            entityData.toString(), true);
}

From source file:org.pentaho.metaverse.api.Namespace.java

@Override
public INamespace getParentNamespace() {
    if (namespace != null) {
        try {/*  w  w w.jav  a2 s .  c  o m*/
            JsonNode jsonObject = objectMapper.readTree(namespace);
            JsonNode namespaceNode = jsonObject.get(DictionaryConst.PROPERTY_NAMESPACE);
            if (namespaceNode == null) {
                return null;
            }
            String parent;

            if (namespaceNode.isTextual()) {
                parent = namespaceNode.asText();
            } else {
                parent = namespaceNode.toString();
            }

            return new Namespace(parent);
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}

From source file:com.dhenton9000.jersey.client.CodeBaseClass.java

protected void updateRestaurant(JsonNode restaurant, String fieldName, String newValue) {

    ClientConfig config = new ClientConfig();
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());

    ObjectNode sampleObj = (ObjectNode) restaurant;
    sampleObj.put(fieldName, newValue);//from  w  w w. j a v a 2  s. c  om
    String newString = restaurant.toString();
    assertTrue(StringUtils.isNotEmpty(newString));

    Entity<String> itemToSend = Entity.json(newString);
    target.path("restaurant").path("4").request(MediaType.APPLICATION_JSON).put(itemToSend);

}

From source file:com.almende.eve.state.AbstractState.java

/**
 * Loc put if unchanged./*from w  w  w  . j  a  v a2s .  c o  m*/
 *
 * @param key the key
 * @param newVal the new val
 * @param oldVal the old val
 * @return true, if successful
 */
public boolean locPutIfUnchanged(final String key, final JsonNode newVal, final JsonNode oldVal) {
    LOG.warning(
            "Warning, this type of State can't store JsonNodes, only Serializable objects. This JsonNode is stored as string.");
    return locPutIfUnchanged(key, newVal.toString(), oldVal.toString());
}

From source file:org.dspace.app.rest.repository.CommunityRestRepository.java

@Override
@PreAuthorize("hasPermission(#id, 'COMMUNITY', 'WRITE')")
protected CommunityRest put(Context context, HttpServletRequest request, String apiCategory, String model,
        UUID id, JsonNode jsonNode)
        throws RepositoryMethodNotImplementedException, SQLException, AuthorizeException {
    CommunityRest communityRest;/*w  ww.ja  v  a  2s.  co  m*/
    try {
        communityRest = new ObjectMapper().readValue(jsonNode.toString(), CommunityRest.class);
    } catch (IOException e) {
        throw new UnprocessableEntityException("Error parsing community json: " + e.getMessage());
    }
    Community community = cs.find(context, id);
    if (community == null) {
        throw new ResourceNotFoundException(apiCategory + "." + model + " with id: " + id + " not found");
    }
    CommunityRest originalCommunityRest = converter.fromModel(community);
    if (communityRestEqualityUtils.isCommunityRestEqualWithoutMetadata(originalCommunityRest, communityRest)) {
        metadataConverter.setMetadata(context, community, communityRest.getMetadata());
    } else {
        throw new UnprocessableEntityException(
                "The given JSON and the original Community differ more " + "than just the metadata");
    }
    return converter.fromModel(community);
}

From source file:com.evrythng.java.wrapper.mapping.ActionJobDeserializer.java

@Override
public ActionJob deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException {

    ObjectMapper mapper = JSONUtils.OBJECT_MAPPER;
    JsonNode node = mapper.readTree(jp);
    JsonNode typeNode = node.get(ActionJob.FIELD_TYPE);
    if (typeNode == null) {
        throw new JsonMappingException("Cannot deserialize actions job without type field");
    }// w w w .  j  a  v  a2s  .  com
    String typeRaw = getFieldValue(typeNode);
    Class<? extends ActionJob> subtypeClass = classForType(ActionJob.Type.valueOf(typeRaw.toUpperCase()));
    return mapper.readValue(node.toString(), subtypeClass);
}

From source file:org.apache.solr.kelvin.App.java

private void configureTestsFromJsonNode(JsonNode node) throws Exception {
    if (testCases == null)
        testCases = new ArrayList<ITestCase>(); //otherwise appends
    ArrayNode list = ConfigurableLoader.assureArray(node);
    for (int i = 0; i < list.size(); i++) {
        JsonNode config = list.get(i);
        try {//from   w  ww. j ava2 s. co m
            ITestCase t = SingletonTestRegistry.instantiate(config);
            t.configure(config);
            testCases.add(t);
        } catch (Exception e) {
            logger.log(Level.SEVERE, "error reading " + config.toString(), e);
        }
    }
}

From source file:com.redhat.lightblue.eval.FieldProjectorTest.java

@Test
public void project_field_without_recursion() throws Exception {
    Projection p = EvalTestContext.projectionFromJson("[{'field':'field2'},{'field':'field6.*'}]");
    Projector projector = Projector.getInstance(p, md);
    JsonNode expectedNode = JsonUtils.json(
            "{'field2':'value2','field6':{'nf1':'nvalue1','nf2':'nvalue2','nf3':4,'nf4':false,'nf5':[],'nf6':[],'nf7':{},'nf8':[],'nf9':[],'nf10':[],'nf11':null}}"
                    .replace('\'', '\"'));

    JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY);

    Assert.assertEquals(expectedNode.toString(), pdoc.toString());
}