當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectNode.arrayNode方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.node.ObjectNode.arrayNode方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectNode.arrayNode方法的具體用法?Java ObjectNode.arrayNode怎麽用?Java ObjectNode.arrayNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.node.ObjectNode的用法示例。


在下文中一共展示了ObjectNode.arrayNode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createItemObject

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
private ObjectNode createItemObject(String collectionUuid, PropBagEx metadata, boolean withAttachment)
{
	ObjectNode item = mapper.createObjectNode();

	ObjectNode collection = item.objectNode();
	collection.put("uuid", collectionUuid);
	item.put("collection", collection);
	item.put("metadata", metadata.toString());
	if( withAttachment )
	{
		ArrayNode attachments = item.arrayNode();
		ObjectNode attachment = item.objectNode();
		attachment.put("type", "url");
		attachment.put("description", "Google");
		attachment.put("url", "http://google.com.au/");
		attachment.put("uuid", "uuid:0");
		attachments.add(attachment);
		item.put("attachments", attachments);
	}
	return item;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:ItemApiEditTest.java

示例2: pathCanReferToArrayContentsByIndex

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
@Test
public void pathCanReferToArrayContentsByIndex() {

    ObjectNode root = new ObjectMapper().createObjectNode();

    ArrayNode a = root.arrayNode();
    root.set("a", a);

    a.add(root.objectNode());
    a.add(root.objectNode());
    a.add(root.objectNode());

    assertThat(resolver.resolve(root, "#/a/0", "#/."), is(sameInstance(a.get(0))));
    assertThat(resolver.resolve(root, "#/a/1", "#/."), is(sameInstance(a.get(1))));
    assertThat(resolver.resolve(root, "#/a/2", "#/."), is(sameInstance(a.get(2))));

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:FragmentResolverTest.java

示例3: addTrackingEvent

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
public static Result addTrackingEvent()
{
    ObjectNode result = Json.newObject();
    String username = session("user");
    ObjectNode json = Json.newObject();
    ArrayNode res = json.arrayNode();
    JsonNode requestNode = request().body().asJson();

    if (StringUtils.isNotBlank(username))
    {
        String message = TrackingDAO.addTrackingEvent(requestNode, username);
        if (StringUtils.isBlank(message))
        {
            result.put("status", "success");
            return ok(result);
        }
        else
        {
            result.put("status", "failed");
            result.put("message", message);
            return badRequest(result);
        }
    }
    else
    {
        result.put("status", "failed");
        result.put("message", "User is not authenticated");
        return unauthorized(result);
    }
}
 
開發者ID:SirAeroWN,項目名稱:premier-wherehows,代碼行數:31,代碼來源:Tracking.java

示例4: dumpBlock

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
public static void dumpBlock(ObjectNode blockNode, Block block,
                                 long gasUsed, byte[] state, List<ByteArrayWrapper> keys,
                                 Repository repository) {

        blockNode.put("coinbase", Hex.toHexString(block.getCoinbase()));
        blockNode.put("difficulty", new BigInteger(1, block.getDifficulty()).toString());
        blockNode.put("extra_data", "0x");
        blockNode.put("gas_used", String.valueOf(gasUsed));
        blockNode.put("nonce", "0x" + Hex.toHexString(block.getNonce()));
        blockNode.put("number", String.valueOf(block.getNumber()));
        blockNode.put("prevhash", "0x" + Hex.toHexString(block.getParentHash()));

        ObjectNode statesNode = blockNode.objectNode();
        for (ByteArrayWrapper key : keys) {
            byte[] keyBytes = key.getData();
            AccountState accountState = repository.getAccountState(keyBytes);
            ContractDetails details = repository.getContractDetails(keyBytes);
            dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
        }
        blockNode.set("state", statesNode);

        blockNode.put("state_root", Hex.toHexString(state));
        blockNode.put("timestamp", String.valueOf(block.getTimestamp()));

        ArrayNode transactionsNode = blockNode.arrayNode();
        blockNode.set("transactions", transactionsNode);

        blockNode.put("tx_list_root", ByteUtil.toHexString(block.getTxTrieRoot()));
        blockNode.put("uncles_hash", "0x" + Hex.toHexString(block.getUnclesHash()));

//      JSONHelper.dumpTransactions(blockNode,
//              stateRoot, codeHash, code, storage);
    }
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:34,代碼來源:JSONHelper.java

示例5: buildPropertyFileNode

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
private ObjectNode buildPropertyFileNode ( File propFile, String serviceName ) {
	//
	ObjectNode propertyNode = jacksonMapper.createObjectNode();
	String targetName = propFile.getName();
	String targetLife = propFile.getParentFile().getName();
	propertyNode.put( ServiceAttributes.FileAttributes.name.json, targetName );
	propertyNode.put( ServiceAttributes.FileAttributes.lifecycle.json, targetLife );
	propertyNode.put( ServiceAttributes.FileAttributes.external.json, "true" );

	// check for working version
	String targetPath = serviceName + "/resources/" + targetLife + "/" + targetName;

	ArrayNode content = propertyNode.arrayNode();
	try (BufferedReader br = new BufferedReader( new FileReader( propFile ) )) {

		String sCurrentLine;

		while ((sCurrentLine = br.readLine()) != null) {
			content.add( sCurrentLine );
		}

	} catch (IOException e) {
		logger.error( "Failed reading file: {}", propFile, e );
	}

	propertyNode.set( ServiceAttributes.FileAttributes.content.json, content );

	return propertyNode;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:30,代碼來源:DefinitionRequests.java

示例6: dumpBlock

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
public static void dumpBlock(ObjectNode blockNode, Block block,
                             long gasUsed, byte[] state, List<ByteArrayWrapper> keys,
                             Repository repository) {

    blockNode.put("coinbase", Hex.toHexString(block.getCoinbase()));
    blockNode.put("difficulty", new BigInteger(1, block.getDifficulty()).toString());
    blockNode.put("extra_data", "0x");
    blockNode.put("gas_used", String.valueOf(gasUsed));

    blockNode.put("bitcoin_merged_mining_header", "0x" + Hex.toHexString(block.getBitcoinMergedMiningHeader()));
    blockNode.put("bitcoin_merged_mining_merkle_proof", "0x" + Hex.toHexString(block.getBitcoinMergedMiningMerkleProof()));
    blockNode.put("bitcoin_merged_mining_coinbase_transaction", "0x" + Hex.toHexString(block.getBitcoinMergedMiningCoinbaseTransaction()));

    blockNode.put("number", String.valueOf(block.getNumber()));
    blockNode.put("prevhash", "0x" + Hex.toHexString(block.getParentHash()));

    ObjectNode statesNode = blockNode.objectNode();
    for (ByteArrayWrapper key : keys) {
        byte[] keyBytes = key.getData();
        AccountState accountState = repository.getAccountState(keyBytes);
        ContractDetails details = repository.getContractDetails(keyBytes);
        dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
    }
    blockNode.set("state", statesNode);

    blockNode.put("state_root", Hex.toHexString(state));
    blockNode.put("timestamp", String.valueOf(block.getTimestamp()));

    ArrayNode transactionsNode = blockNode.arrayNode();
    blockNode.set("transactions", transactionsNode);

    blockNode.put("tx_list_root", ByteUtil.toHexString(block.getTxTrieRoot()));
    blockNode.put("uncles_hash", "0x" + Hex.toHexString(block.getUnclesHash()));
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:35,代碼來源:JSONHelper.java

示例7: testEditEverything

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
@Test
public void testEditEverything() throws Exception
{
	final String token = getToken();
	ItemId itemId = createItem(token);
	// get item
	ObjectNode item = getItem(itemId, "all", token);

	// check all nodes
	assertNameVersionStatus(item, "ItemApiEditTest - All attachments from JSON", 1, "live");
	assertMetadata(item, "item/name", "ItemApiEditTest - All attachments from JSON");
	asserter.assertUser(item.get("owner"), USERID_AUTOTEST);
	asserter.assertUser(item.get("collaborators").get(0), USERID_RESTNOPRIV);
	asserter.assertCollection(item.get("collection"), COLLECTION_ATTACHMENTS);
	assertUrlAttachment(item.get("attachments").get(2), itemId);
	assertFirstNavNode(item.get("navigation").get("nodes"), "avatar.png");

	// modify metadata
	PropBagEx metadata = new PropBagEx(item.get("metadata").textValue());
	metadata.setNode("item/name", "ItemApiEditTest - All attachments from JSON - Edited");
	item.put("metadata", metadata.toString());

	// modify owner
	ObjectNode owner = item.objectNode();
	owner.put("id", USERID_RESTNOPRIV);
	item.put("owner", owner);

	// modify collaborators
	ArrayNode collaborators = item.arrayNode();
	ObjectNode collaborator = item.objectNode();
	collaborator.put("id", USERID_AUTOTEST);
	collaborators.add(collaborator);
	item.put("collaborators", collaborators);

	// Future enhancement
	// modify collection
	// ObjectNode collection = item.objectNode();
	// collection.put("uuid", PERMISSIONS_COLLECTION);
	// item.put("collection", collection);

	// modify attachments
	ObjectNode attachment = (ObjectNode) item.get("attachments").get(2);
	attachment.put("description", "Yahoo");
	attachment.put("url", "http://www.yahoo.com");

	// modify navigation
	ObjectNode node = (ObjectNode) item.get("navigation").get("nodes").get(0);
	node.put("name", "An awesome image");

	// save
	HttpResponse response = putItem(itemId, item.toString(), token);
	assertResponse(response, 200, "Save should work");

	// check that its correct
	item = getItem(itemId, "all", token);
	assertNameVersionStatus(item, "ItemApiEditTest - All attachments from JSON - Edited", 1, "live");
	assertMetadata(item, "item/name", "ItemApiEditTest - All attachments from JSON - Edited");
	asserter.assertUser(item.get("owner"), USERID_RESTNOPRIV);
	asserter.assertUser(item.get("collaborators").get(0), USERID_AUTOTEST);

	// Future enhancement
	// asserter.assertCollection(item.get("collection"),
	// PERMISSIONS_COLLECTION);

	assertUrlAttachment(item.get("attachments").get(2), itemId, "Yahoo", "http://www.yahoo.com");
	assertFirstNavNode(item.get("navigation").get("nodes"), "An awesome image");

}
 
開發者ID:equella,項目名稱:Equella,代碼行數:69,代碼來源:ItemApiEditTest.java

示例8: testEditNoPrivs

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
@Test
public void testEditNoPrivs() throws Exception
{
	PropBagEx metadata = new PropBagEx(
		"<xml><item><name>ItemApiEditTest - No Permissions from JSON</name><description>Description</description><controls></controls></item></xml>");
	PropBagEx permissions = metadata.aquireSubtree("item/controls");

	final String token = getToken();

	ObjectNode item = createItemObject(COLLECTION_PERMISSIONS, metadata, false);

	ItemId itemId = addDeletable(createItem(item.toString(), token));

	item = getItem(itemId, "all", token);
	assertNameVersionStatus(item, "ItemApiEditTest - No Permissions from JSON", 1, "live");

	// revoke change owner
	permissions.setNode("checkboxes", "REASSIGN_OWNERSHIP_ITEM");
	item.put("metadata", metadata.toString());
	HttpResponse response = putItem(itemId, item.toString(), token);
	assertResponse(response, 200, "200 not returned from item editing");

	item.put("owner", USERID_RESTNOPRIV);
	ObjectNode error = putItemError(getItemUri(itemId), item.toString(), token, 403);
	assertError(error, 403, "Forbidden",
		"Privilege REASSIGN_OWNERSHIP_ITEM is required to perform the requested operation");
	item = getItem(itemId, "all", token);
	ArrayNode collabs = item.arrayNode();
	collabs.add(USERID_RESTNOPRIV);
	collabs.add(USERID_AUTOTEST);
	item.put("collaborators", collabs);
	error = putItemError(getItemUri(itemId), item.toString(), token, 403);
	assertError(error, 403, "Forbidden",
		"Privilege REASSIGN_OWNERSHIP_ITEM is required to perform the requested operation");
	item = getItem(itemId, "all", token);

	// revoke edit
	permissions.setNode("checkboxes", "EDIT_ITEM");
	item.put("metadata", metadata.toString());
	response = putItem(itemId, item.toString(), token);
	assertResponse(response, 200, "200 not returned from item editing");

	// try to change the name
	PropBagEx editNameMetadata = new PropBagEx(metadata.toString());
	editNameMetadata.setNode("item/name", "ItemApiEditTest - No Permissions from JSON - Edited");
	item.put("metadata", editNameMetadata.toString());
	error = putItemError(getItemUri(itemId), item.toString(), token, 403);
	assertError(error, 403, "Forbidden", "Privilege EDIT_ITEM is required to perform the requested operation");

	// try to edit drm
	item.put("metadata", metadata.toString());
	item.with("drm").with("options").put("termsOfAgreement", "Terms");
	error = putItemError(getItemUri(itemId), item.toString(), token, 403);
	assertError(error, 403, "Forbidden", "Privilege EDIT_ITEM is required to perform the requested operation");

	item = getItem(itemId, "all", token);
	assertNameVersionStatus(item, "ItemApiEditTest - No Permissions from JSON", 1, "live");
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:59,代碼來源:ItemApiEditTest.java

示例9: attemptToUsePropertyNameOnArrayNodeThrowsIllegalArgumentException

import com.fasterxml.jackson.databind.node.ObjectNode; //導入方法依賴的package包/類
@Test(expected = IllegalArgumentException.class)
public void attemptToUsePropertyNameOnArrayNodeThrowsIllegalArgumentException() {

    ObjectNode root = new ObjectMapper().createObjectNode();

    ArrayNode a = root.arrayNode();
    root.set("a", a);

    resolver.resolve(root, "#/a/b", "#/.");

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:FragmentResolverTest.java


注:本文中的com.fasterxml.jackson.databind.node.ObjectNode.arrayNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。