Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#arrayNode()

The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode#arrayNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToJson.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
public ObjectNode toJson(WorkflowBundle wfBundle) {

		ObjectNode root = mapper.createObjectNode();
		ArrayNode contextList = root.arrayNode();
		root.put("@context", contextList);
		ObjectNode context = root.objectNode();
		contextList.add("https://w3id.org/scufl2/context");
		contextList.add(context);
		URI base = wfBundle.getGlobalBaseURI();
		context.put("@base", base.toASCIIString());
		root.put("id", base.toASCIIString());

		// root.put("name", wfBundle.getName());
		// root.put("revisions", toJson(wfBundle.getCurrentRevision()));

		root.put("workflow", toJson(wfBundle.getMainWorkflow()));
		root.put("profile", toJson(wfBundle.getMainProfile()));

		return root;
	}
 
Example 2
Source File: JsonExport.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
public ObjectNode toJson(WorkflowBundle wfBundle) {
        
        ObjectNode root = mapper.createObjectNode();
        ArrayNode contextList = root.arrayNode();
        root.put("@context", contextList);
        ObjectNode context = root.objectNode();
        contextList.add("https://w3id.org/scufl2/context");
        contextList.add(context);
        URI base = wfBundle.getGlobalBaseURI();
        context.put("@base", base.toASCIIString());
        root.put("id", base.toASCIIString());
       
//        root.put("name", wfBundle.getName());
//        root.put("revisions", toJson(wfBundle.getCurrentRevision()));
        
        root.put("workflow", toJson(wfBundle.getMainWorkflow()));
        root.put("profile", toJson(wfBundle.getMainProfile()));
        
        return root;
    }
 
Example 3
Source File: SpreadsheetActivityParser.java    From incubator-taverna-language with Apache License 2.0 5 votes vote down vote up
private void makeRange(SpreadsheetRange range, ObjectNode rangeJson) {
	rangeJson.put("start", range.getStart().longValue());
       rangeJson.put("end", range.getEnd().longValue());
       
       ArrayNode excludes = rangeJson.arrayNode();
	for (SpreadsheetRange excludesRange : range.getExcludes().getExclude()) {
		ObjectNode exclude = rangeJson.objectNode();
		makeRange(excludesRange, exclude);
	    excludes.add(exclude);
	}
	if (excludes.size() > 0)
	    rangeJson.put("excludes", excludes);
}
 
Example 4
Source File: JSONHelper.java    From ethereumj with MIT License 5 votes vote down vote up
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.calcDifficulty()).toString());
    	blockNode.put("extra_data", "0x");
    	blockNode.put("gas_limit", String.valueOf(block.calcGasLimit()));
    	blockNode.put("gas_used", String.valueOf(gasUsed));
    	blockNode.put("min_gas_price", String.valueOf(block.getMinGasPrice()));
    	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);
            JSONHelper.dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
        }       
        blockNode.put("state", statesNode);
        
        blockNode.put("state_root", Hex.toHexString(state));
        blockNode.put("timestamp", String.valueOf(block.getTimestamp()));
        
        ArrayNode transactionsNode = blockNode.arrayNode();
        blockNode.put("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);
    }
 
Example 5
Source File: XPathActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser,
		ConfigBean configBean, ParserState parserState)
		throws ReaderException {

	XPathConfig xpathConfig = unmarshallConfig(t2FlowParser, configBean,
			"xstream", XPathConfig.class);

	Configuration configuration = new Configuration();
	configuration.setParent(parserState.getCurrentProfile());
	parserState.setCurrentConfiguration(configuration);

	try {
	    
	    ObjectNode json = (ObjectNode)configuration.getJson();
	    configuration.setType(ACTIVITY_URI.resolve("#Config"));

		String xmlDocument = xpathConfig.getXmlDocument();
		if (xmlDocument != null) {
		    json.put("exampleXmlDocument", xmlDocument);
		}

		String xpathExpression = xpathConfig.getXpathExpression();
		json.put("xpathExpression", xpathExpression);

		
		ArrayNode namespaceMap = json.arrayNode();
		json.put("xpathNamespaceMap", namespaceMap);

		// TODO look at why the schema translation here is so wrong
		for (Entry list : xpathConfig.getXpathNamespaceMap().getEntry()) {
			String namespacePrefix = list.getContent().get(0).getValue();
			String namespaceURI = list.getContent().get(1).getValue();

			ObjectNode map = json.objectNode();
			map.put("prefix", namespacePrefix);
			map.put("uri", namespaceURI);
			namespaceMap.add(map);
		}
	} finally {
		parserState.setCurrentConfiguration(null);
	}
	return configuration;
}
 
Example 6
Source File: SpreadsheetActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
		ParserState parserState) throws ReaderException {
	SpreadsheetImportConfig config = unmarshallConfig(t2FlowParser, configBean, "xstream",
			SpreadsheetImportConfig.class);

	Configuration configuration = new Configuration();
	configuration.setParent(parserState.getCurrentProfile());

	ObjectNode json = (ObjectNode) configuration.getJson();
	configuration.setType(ACTIVITY_URI.resolve("#Config"));

	ObjectNode columnRange = json.objectNode();
	json.put("columnRange", columnRange);
	makeRange(config.getColumnRange(), columnRange);

	ObjectNode rowRange = json.objectNode();
       json.put("rowRange", rowRange);
       makeRange(config.getRowRange(), rowRange);

	if (config.getEmptyCellValue() != null)
	    json.put("emptyCellValue", config.getEmptyCellValue());
	
	ArrayNode columnNames = json.arrayNode();
       if (config.getColumnNames() != null && config.getColumnNames().getEntry() != null) {
   		for (SpreadsheetColumnNameEntry entry : config.getColumnNames().getEntry()) {
   		    ObjectNode mapping = json.objectNode();
   		    columnNames.add(mapping);
               mapping.put("column", entry.getString().get(0));
               mapping.put("port", entry.getString().get(1));
   		}
   		if (columnNames.size() > 0)
   		    json.put("columnNames", columnNames);
       }
	
	json.put("allRows", config.isAllRows());
	json.put("excludeFirstRow", config.isExcludeFirstRow());
	json.put("ignoreBlankRows", config.isIgnoreBlankRows());
	if (config.getEmptyCellPolicy() != null)
		json.put("emptyCellPolicy", config.getEmptyCellPolicy().value());
	if (config.getOutputFormat() != null)
		json.put("outputFormat", config.getOutputFormat().value());
	if (config.getCsvDelimiter() != null)
		json.put("csvDelimiter", config.getCsvDelimiter());

	return configuration;
}
 
Example 7
Source File: ApiConsomerActivityParser.java    From incubator-taverna-language with Apache License 2.0 4 votes vote down vote up
@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser,
		ConfigBean configBean, ParserState parserState)
		throws ReaderException {
	ApiConsumerConfig config = unmarshallConfig(t2FlowParser, configBean,
			"xstream", ApiConsumerConfig.class);

	Configuration configuration = new Configuration();
	configuration.setParent(parserState.getCurrentProfile());

	ObjectNode json = (ObjectNode) configuration.getJson();
	configuration.setType(ACTIVITY_URI.resolve("#Config"));

	json.put("apiConsumerDescription", config.getApiConsumerDescription());
	json.put("apiConsumerName", config.getApiConsumerName());
	json.put("description", config.getDescription());
	json.put("className", config.getClassName());
	json.put("methodName", config.getMethodName());

	ArrayNode parameterNames = json.arrayNode();
	json.put("parameterNames", parameterNames);
	for (String parameterName : config.getParameterNames().getString())
		parameterNames.add(parameterName);

	ArrayNode parameterDimensions = json.arrayNode();
	json.put("parameterDimensions", parameterDimensions);
	for (BigInteger parameterDimension : config.getParameterDimensions()
			.getInt())
		parameterDimensions.add(parameterDimension.intValue());

	ArrayNode parameterTypes = json.arrayNode();
	json.put("parameterTypes", parameterTypes);
	for (String parameterType : config.getParameterTypes().getString())
		parameterTypes.add(parameterType);

	json.put("returnType", config.getReturnType());
	json.put("returnDimension", config.getReturnDimension().intValue());
	json.put("isMethodConstructor", config.isIsMethodConstructor());
	json.put("isMethodStatic", config.isIsMethodStatic());

	return configuration;
}