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

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

Introduction

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

Prototype

public String toString() 

Source Link

Usage

From source file:org.opendaylight.sfc.sbrest.json.AclExporterFactory.java

@Override
public String exportJsonNameOnly(DataObject dataObject) {

    String ret = null;//w  w w  .  ja  va 2 s  .c o m
    if (dataObject instanceof Acl) {
        Acl acl = (Acl) dataObject;

        ObjectNode aclNode = mapper.createObjectNode();
        aclNode.put(_ACL_NAME, acl.getAclName());
        ArrayNode aclArray = mapper.createArrayNode();
        aclArray.add(aclNode);

        ret = "{\"" + _ACL + "\":" + aclArray.toString() + "}";
        LOG.debug("Created Access List JSON: {}", ret);

    } else {
        throw new IllegalArgumentException("Argument is not an instance of Access List");
    }

    return ret;
}

From source file:org.opendaylight.sfc.sbrest.json.SfstateExporterFactory.java

@Override
public String exportJsonNameOnly(DataObject dataObject) {
    String ret = null;/*from ww w  .j av a  2  s. com*/

    if (dataObject instanceof ServiceFunctionState) {
        ServiceFunctionState obj = (ServiceFunctionState) dataObject;

        ObjectNode node = mapper.createObjectNode();
        if (obj.getName() != null) {
            node.put(_NAME, obj.getName().getValue());
        }
        ArrayNode sfstateArray = mapper.createArrayNode();
        sfstateArray.add(node);
        ret = "{\"" + _SERVICE_FUNCTION_STATE + "\":" + sfstateArray.toString() + "}";
    } else {
        throw new IllegalArgumentException("Argument is not an instance of ServiceFunctionState");
    }

    return ret;
}

From source file:org.kiji.rest.TestKijiRestEntityId.java

@Test
public void testShouldCreateListsOfEntityIds() throws Exception {
    final TableLayoutDesc desc = KijiTableLayouts.getLayout("org/kiji/rest/layouts/rkf_hashprefixed.json");
    final KijiTableLayout layout = KijiTableLayout.newLayout(desc);
    final EntityIdFactory factory = EntityIdFactory.getFactory(layout);
    final byte[] rowKey = Bytes.toBytes(UNUSUAL_STRING_EID);
    final EntityId originalEid = factory.getEntityIdFromHBaseRowKey(rowKey);

    // test the creation of entity ids from raw hbase rowkey
    final KijiRestEntityId restEid1 = KijiRestEntityId.createFromUrl(
            String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))), layout);
    final KijiRestEntityId restEid2 = KijiRestEntityId.createFromUrl(
            String.format("hbase=%s", Bytes.toStringBinary(originalEid.getHBaseRowKey())), layout);

    final JsonNodeFactory jsonNodeFactory = new JsonNodeFactory(true);
    final JsonNode hbaseHexStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    final JsonNode hbaseBinaryStringNode = jsonNodeFactory
            .textNode(String.format("hbase_hex=%s", new String(Hex.encodeHex(originalEid.getHBaseRowKey()))));
    ArrayNode hbaseListNode = jsonNodeFactory.arrayNode();
    hbaseListNode.add(hbaseHexStringNode);
    hbaseListNode.add(hbaseBinaryStringNode);

    final List<KijiRestEntityId> restEidList1 = KijiRestEntityId.createListFromUrl(hbaseListNode.toString(),
            layout);/*  w  ww. j  a  v a  2 s .  c om*/

    assertEquals(restEid1.resolve(layout), restEidList1.get(0).resolve(layout));
    assertEquals(restEid2.resolve(layout), restEidList1.get(1).resolve(layout));

    // test the creation of entity ids from various json strings
    final KijiRestEntityId restEid3 = KijiRestEntityId.createFromUrl("[\"Hello\",\"World\"]", layout);
    final List<KijiRestEntityId> restEidList3 = KijiRestEntityId.createListFromUrl("[[\"Hello\",\"World\"]]",
            layout);
    final KijiRestEntityId restEid4 = KijiRestEntityId.createFromUrl("[[],\"World\"]", layout);
    final List<KijiRestEntityId> restEidList4 = KijiRestEntityId
            .createListFromUrl("[[[],\"World\"],[\"Hello\",\"World\"]]", layout);

    assertEquals(restEid3.resolve(layout), restEidList3.get(0).resolve(layout));
    assertEquals(restEid4.getStringEntityId(), restEidList4.get(0).getStringEntityId());
    assertEquals(1, restEidList3.size());
    assertEquals(2, restEidList4.size());
}

From source file:ijfx.service.ui.ImageJInfoService.java

@AngularMethod(sync = true, description = "Return the list of all widgets", inputDescription = "No input")
public JSObject getModuleList() {
    try {//from   w  w w.j  av  a 2 s  . c  om
        ObjectMapper mapper = new ObjectMapper();
        logger.fine("Getting module list");
        SimpleModule simpleModule = new SimpleModule("ModuleSerializer");
        // simpleModule.addSerializer(ModuleItem<?>.class,new ModuleItemSerializer());
        simpleModule.addSerializer(ModuleInfo.class, new ModuleSerializer());
        simpleModule.addSerializer(ModuleItem.class, new ModuleItemSerializer());
        mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        mapper.registerModule(simpleModule);

        ArrayNode arrayNode = mapper.createArrayNode();

        moduleService.getModules().forEach(module -> {

            //System.out.println("Adding "+module.getName());
            arrayNode.add(mapper.convertValue(module, JsonNode.class));

        });

        //String json = mapper.writeValueAsString(moduleService.getModules());
        logger.fine("JSON done !");

        return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), arrayNode.toString());
        //return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), json);

    } catch (Exception ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    logger.warning("Returning null");
    return null;
}

From source file:com.glaf.base.modules.branch.springmvc.BranchDepartmentController.java

@ResponseBody
@RequestMapping(params = "method=treeJson")
public byte[] treeJson(HttpServletRequest request) {
    logger.debug("------------------------treeJson--------------------");
    String actorId = RequestUtils.getActorId(request);
    List<TreeModel> treeModels = complexUserService.getUserManageBranch(actorId);
    logger.debug("#treeModels:" + treeModels);
    JacksonTreeHelper treeHelper = new JacksonTreeHelper();
    ArrayNode responseJSON = treeHelper.getTreeArrayNode(treeModels);
    try {/*  www.  j ava  2s. c  o m*/
        return responseJSON.toString().getBytes("UTF-8");
    } catch (IOException e) {
        return responseJSON.toString().getBytes();
    }
}

From source file:com.redhat.lightblue.rest.metadata.hystrix.GetEntityVersionsCommand.java

@Override
protected String run() {
    LOGGER.debug("run: entity={}", entity);
    Error.reset();//from   ww w  .  j ava2  s  .  c  o m
    Error.push(getClass().getSimpleName());
    try {
        VersionInfo[] versions = getMetadata().getEntityVersions(entity);
        ArrayNode arr = NODE_FACTORY.arrayNode();

        for (VersionInfo x : versions) {
            ObjectNode obj = NODE_FACTORY.objectNode();
            obj.put("version", x.getValue());
            obj.put("changelog", x.getChangelog());
            ArrayNode ev = NODE_FACTORY.arrayNode();
            if (x.getExtendsVersions() != null) {
                for (String v : x.getExtendsVersions()) {
                    ev.add(NODE_FACTORY.textNode(v));
                }
            }
            obj.set("extendsVersions", ev);
            obj.put("status", MetadataParser.toString(x.getStatus()));
            obj.put("defaultVersion", x.isDefault());
            arr.add(obj);
        }
        return arr.toString();
    } catch (Error e) {
        return e.toString();
    } catch (Exception e) {
        LOGGER.error("Failure: {}", e);
        return Error.get(RestMetadataConstants.ERR_REST_ERROR, e.toString()).toString();
    }
}

From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java

/**
 * Test creating a single process variable, testing default types when omitted. POST runtime/process-instances/{processInstanceId}/variables
 *///from www  . j  a v a 2s .  c o  m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessVariableDefaultTypes() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    // String type detection
    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode varNode = requestNode.addObject();
    varNode.put("name", "stringVar");
    varNode.put("value", "String value");

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals("String value", runtimeService.getVariable(processInstance.getId(), "stringVar"));

    // Integer type detection
    varNode.put("name", "integerVar");
    varNode.put("value", 123);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(123, runtimeService.getVariable(processInstance.getId(), "integerVar"));

    // Double type detection
    varNode.put("name", "doubleVar");
    varNode.put("value", 123.456);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(123.456, runtimeService.getVariable(processInstance.getId(), "doubleVar"));

    // Boolean type detection
    varNode.put("name", "booleanVar");
    varNode.put("value", Boolean.TRUE);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(Boolean.TRUE, runtimeService.getVariable(processInstance.getId(), "booleanVar"));
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java

/**
 * Test creating a single process variable, testing default types when omitted. POST runtime/process-instances/{processInstanceId}/variables
 *//*from www  .  j  a  va2s. com*/
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessVariableDefaultTypes() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

    // String type detection
    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode varNode = requestNode.addObject();
    varNode.put("name", "stringVar");
    varNode.put("value", "String value");

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals("String value", runtimeService.getVariable(processInstance.getId(), "stringVar"));

    // Integer type detection
    varNode.put("name", "integerVar");
    varNode.put("value", 123);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(123, runtimeService.getVariable(processInstance.getId(), "integerVar"));

    // Double type detection
    varNode.put("name", "doubleVar");
    varNode.put("value", 123.456);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(123.456, runtimeService.getVariable(processInstance.getId(), "doubleVar"));

    // Boolean type detection
    varNode.put("name", "booleanVar");
    varNode.put("value", Boolean.TRUE);

    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CREATED));

    assertEquals(Boolean.TRUE, runtimeService.getVariable(processInstance.getId(), "booleanVar"));
}

From source file:org.activiti.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java

/**
 * Test creating a single process variable, testing edge case exceptions. POST runtime/process-instances/{processInstanceId}/variables
 *///w  w  w.j av  a 2  s. c  o m
@Deployment(resources = {
        "org/activiti/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessVariableEdgeCases() throws Exception {
    // Test adding variable to unexisting execution
    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode variableNode = requestNode.addObject();
    variableNode.put("name", "existingVariable");
    variableNode.put("value", "simple string value");
    variableNode.put("type", "string");

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, "unexisting"));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND));

    // Test trying to create already existing variable
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    runtimeService.setVariable(processInstance.getId(), "existingVariable", "I already exist");

    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));

    // Test creating nameless variable
    variableNode.removeAll();
    variableNode.put("value", "simple string value");

    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    // Test passing in empty array
    requestNode.removeAll();
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    // Test passing in object instead of array
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
}

From source file:org.flowable.rest.service.api.runtime.ProcessInstanceVariablesCollectionResourceTest.java

/**
 * Test creating a single process variable, testing edge case exceptions. POST runtime/process-instances/{processInstanceId}/variables
 *///from   ww  w. ja v  a  2 s .c om
@Deployment(resources = {
        "org/flowable/rest/service/api/runtime/ProcessInstanceVariablesCollectionResourceTest.testProcess.bpmn20.xml" })
public void testCreateSingleProcessVariableEdgeCases() throws Exception {
    // Test adding variable to unexisting execution
    ArrayNode requestNode = objectMapper.createArrayNode();
    ObjectNode variableNode = requestNode.addObject();
    variableNode.put("name", "existingVariable");
    variableNode.put("value", "simple string value");
    variableNode.put("type", "string");

    HttpPost httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls
            .createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, "unexisting"));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_NOT_FOUND));

    // Test trying to create already existing variable
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    runtimeService.setVariable(processInstance.getId(), "existingVariable", "I already exist");

    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_CONFLICT));

    // Test creating nameless variable
    variableNode.removeAll();
    variableNode.put("value", "simple string value");

    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    // Test passing in empty array
    requestNode.removeAll();
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(requestNode.toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));

    // Test passing in object instead of array
    httpPost = new HttpPost(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(
            RestUrls.URL_PROCESS_INSTANCE_VARIABLE_COLLECTION, processInstance.getId()));
    httpPost.setEntity(new StringEntity(objectMapper.createObjectNode().toString()));
    closeResponse(executeRequest(httpPost, HttpStatus.SC_BAD_REQUEST));
}