当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.createArrayNode方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.createArrayNode方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.createArrayNode方法的具体用法?Java ObjectMapper.createArrayNode怎么用?Java ObjectMapper.createArrayNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.createArrayNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendSlackImageResponse

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void sendSlackImageResponse(ObjectNode json, String s3Key) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		ObjectNode message = mapper.createObjectNode();
		ArrayNode attachments = mapper.createArrayNode();
		ObjectNode attachment = mapper.createObjectNode();

		String emoji = json.get("text").asText();

		if (UrlValidator.getInstance().isValid(emoji)) {
			attachment.put("title_link", emoji);
			emoji = StringUtils.substringAfterLast(emoji, "/");
		}

		String username = json.get("user_name").asText();
		String responseUrl = json.get("response_url").asText();
		String slackChannelId = json.get("channel_id").asText();
		String imageUrl = String.format("https://s3.amazonaws.com/%s/%s", PROPERTIES.getProperty(S3_BUCKET_NAME), s3Key);

		message.put("response_type", "in_channel");
		message.put("channel_id", slackChannelId);
		attachment.put("title", resolveMessage("slackImageResponse", emoji, username));
		attachment.put("fallback", resolveMessage("approximated", emoji));
		attachment.put("image_url", imageUrl);
		attachments.add(attachment);
		message.set("attachments", attachments);

		HttpClient client = HttpClientBuilder.create().build();
		HttpPost slackResponseReq = new HttpPost(responseUrl);
		slackResponseReq.setEntity(new StringEntity(mapper.writeValueAsString(message), ContentType.APPLICATION_JSON));
		HttpResponse slackResponse = client.execute(slackResponseReq);
		int status = slackResponse.getStatusLine().getStatusCode();
		LOG.info("Got {} status from Slack API after sending approximation to response url.", status);
	} catch (UnsupportedOperationException | IOException e) {
		LOG.error("Exception occured when sending Slack response", e);
	}
}
 
开发者ID:villeau,项目名称:pprxmtr,代码行数:38,代码来源:Handler.java

示例2: setCategory_sets_the_category_of_Media_of_type_StockFileCategory

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test(groups = { "Setters" })
void setCategory_sets_the_category_of_Media_of_type_StockFileCategory()
        throws NoSuchFieldException, IllegalAccessException,
        JsonProcessingException, IOException {
    stockFile.setCategory(null);
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode node = mapper.createArrayNode();
    stockFile.setCategory(node);
    String jsonString = "{\"name\":\"Text\", \"id\":1}";
    JsonNode jsonNode = mapper.readTree(jsonString);
    stockFile.setCategory(jsonNode);
    Field f = stockFile.getClass().getDeclaredField("mCategory");
    f.setAccessible(true);
    StockFileCategory category = (StockFileCategory) f.get(stockFile);
    Assert.assertEquals(category.getId().intValue(), 1);
    Assert.assertTrue(category.getName().equals("Text"));

}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:19,代码来源:StockFileTest.java

示例3: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Produces JSON object for a topology event.
 *
 * @param mapper the JSON object mapper to use
 * @param event the topology event with the data
 * @return JSON object for the topology event
 */
private ObjectNode json(ObjectMapper mapper, Event event) {
    ObjectNode result = mapper.createObjectNode();

    result.put("time", event.time())
        .put("type", event.type().toString())
        .put("event", event.toString());

    // Add the reasons if a TopologyEvent
    if (event instanceof TopologyEvent) {
        TopologyEvent topologyEvent = (TopologyEvent) event;
        ArrayNode reasons = mapper.createArrayNode();
        for (Event reason : topologyEvent.reasons()) {
            reasons.add(json(mapper, reason));
        }
        result.set("reasons", reasons);
    }

    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:TopologyEventsListCommand.java

示例4: includeElementField

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void includeElementField(String dbName, String field_name, String namespace, String elementName) throws Exception{
	ObjectMapper mapper = new ObjectMapper();
	//	ObjectNode mainNode = mapper.createObjectNode();
	ObjectNode childNode = mapper.createObjectNode();
	ArrayNode arrNode = mapper.createArrayNode();
	ObjectNode childNodeObject = mapper.createObjectNode();
	childNodeObject.put( "namespace-uri", namespace);
	childNodeObject.put( "localname", elementName);
	childNodeObject.put("weight", 1.0);
	arrNode.add(childNodeObject);
	childNode.putArray("included-element").addAll(arrNode);
	//	mainNode.put("included-elements", childNode);
	System.out.println( childNode.toString());
	setDatabaseFieldProperties(dbName,field_name,"included-element",childNode);

}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:17,代码来源:ConnectedRESTQA.java

示例5: getJsonDependencies

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static ArrayNode getJsonDependencies(List<Artifact> artifacts, List<Dependency> directDependencies) {
    HashMap<String, String> requirements = new HashMap<String, String>(directDependencies.size());
    for (Dependency dep : directDependencies) {
        requirements.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion());
    }

    ObjectMapper mapper = new ObjectMapper();
    ArrayNode arrayNode = mapper.createArrayNode();
    for (Artifact art : artifacts) {
        ObjectNode artNode = depToJsonNode(mapper, art);
        String requirement;
        requirement = requirements.get(art.getGroupId() + ":" + art.getArtifactId());
        // Temporary workaround for transitive dependencies
        if (requirement == null){
            requirement = art.getVersion();
        }
        artNode.put("requirement", requirement);
        arrayNode.add(artNode);
    }
    return arrayNode;
}
 
开发者ID:gemnasium,项目名称:gemnasium-maven-plugin,代码行数:22,代码来源:ProjectsUtils.java

示例6: addField

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void addField(String dbName, String fieldName) throws Exception{
	ObjectMapper mapper = new ObjectMapper();
	//	ObjectNode mainNode = mapper.createObjectNode();
	ObjectNode childNode = mapper.createObjectNode();
	ArrayNode arrNode = mapper.createArrayNode();
	ObjectNode childNodeObject = mapper.createObjectNode();
	childNodeObject.put( "field-name", fieldName);
	childNodeObject.put( "include-root", true);
	childNodeObject.putNull( "included-elements");
	childNodeObject.putNull( "excluded-elements");
	childNodeObject.putNull( "tokenizer-overrides");
	arrNode.add(childNodeObject);
	childNode.putArray("field").addAll(arrNode);
	//		mainNode.put("fields", childNode);
	// 		   System.out.println("Entered field to make it true");
	setDatabaseProperties(dbName,"field",childNode);

}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:19,代码来源:ConnectedRESTQA.java

示例7: addRangeElementAttributeIndex

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void addRangeElementAttributeIndex(String dbName, String type, String parentnamespace, String parentlocalname, String namespace, String localname, String collation) throws Exception{
	ObjectMapper mapper = new ObjectMapper();
	//	ObjectNode mainNode = mapper.createObjectNode();
	ObjectNode childNode = mapper.createObjectNode();
	ArrayNode childArray = mapper.createArrayNode();
	ObjectNode childNodeObject = mapper.createObjectNode();
	childNodeObject.put( "scalar-type", type);
	childNodeObject.put( "collation", collation);
	childNodeObject.put( "parent-namespace-uri", parentnamespace);
	childNodeObject.put( "parent-localname", parentlocalname);
	childNodeObject.put( "namespace-uri", namespace);
	childNodeObject.put( "localname", localname);

	childNodeObject.put("range-value-positions", false);
	childNodeObject.put("invalid-values", "reject");
	childArray.add(childNodeObject);
	childNode.putArray("range-element-attribute-index").addAll(childArray);

	//	mainNode.put("range-element-attribute-indexes", childNode);
	//		System.out.println(type + mainNode.path("range-element-attribute-indexes").path("range-element-attribute-index").toString());
	setDatabaseProperties(dbName,"range-element-attribute-index",childNode);

}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:24,代码来源:ConnectedRESTQA.java

示例8: addGeospatialPathIndexes

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void addGeospatialPathIndexes(String dbName,String pathExpression,String coordinateSystem,String pointFormat,boolean rangeValuePositions,String invalidValues) throws Exception{
	ObjectMapper mapper = new ObjectMapper();
	//	ObjectNode mainNode = mapper.createObjectNode();
	ObjectNode childNode = mapper.createObjectNode();
	ArrayNode childArray = mapper.createArrayNode();
	ObjectNode childNodeObject = mapper.createObjectNode();
	childNodeObject.put( "path-expression", pathExpression);
	childNodeObject.put( "coordinate-system", coordinateSystem);
	childNodeObject.put("range-value-positions", false);
	childNodeObject.put("invalid-values", invalidValues);
	childNodeObject.put("point-format",pointFormat);
	childArray.add(childNodeObject);
	childNode.putArray("geospatial-path-index").addAll(childArray);
	//		mainNode.put("geospatial-path-indexes", childNode);
	//			System.out.println(type + mainNode.path("range-path-indexes").path("range-path-index").toString());
	setDatabaseProperties(dbName,"geospatial-path-index",childNode);
}
 
开发者ID:marklogic,项目名称:marklogic-rdf4j,代码行数:18,代码来源:ConnectedRESTQA.java

示例9: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Returns JSON node representing the specified devices.
 *
 * @param devices collection of devices
 * @return JSON node
 */
private JsonNode json(Iterable<Device> devices) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (Device device : devices) {
        result.add(jsonForEntity(device, Device.class));
    }
    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:15,代码来源:DevicesListCommand.java

示例10: scriptingLoadAll

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody ArrayNode scriptingLoadAll() throws ServiceException, JsonProcessingException {
	logger.info("Load All");
	User user = authentificationUtils.getAuthentificatedUser();
	try {
		List<Script> scripts = scriptingService.loadAllScripts();

		ObjectMapper mapper = new ObjectMapper();
		ArrayNode array = mapper.createArrayNode();

		for (Script script : scripts) {
			JsonNode rootNode = mapper.createObjectNode();
			User user1 = userService.findById(script.getCreationUserId());

			((ObjectNode) rootNode).put("id", script.getId());
			((ObjectNode) rootNode).put("title", script.getTitle());
			((ObjectNode) rootNode).put("content", script.getContent());
			((ObjectNode) rootNode).put("creation_date", script.getCreationDate().toString());
			((ObjectNode) rootNode).put("creation_user", user1.getFirstName() + " " + user1.getLastName());
			array.add(rootNode);
		}

		return array;
	} finally {
		authentificationUtils.allowUser(user);
	}
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:28,代码来源:ScriptingController.java

示例11: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Produces a JSON array of BGP neighbors.
 *
 * @param bgpSessions the BGP sessions with the data
 * @return JSON array with the neighbors
 */
private JsonNode json(Collection<BgpSession> bgpSessions) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    for (BgpSession bgpSession : bgpSessions) {
        result.add(json(mapper, bgpSession));
    }
    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:BgpNeighborsListCommand.java

示例12: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private JsonNode json(List<UiExtension> extensions) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode node = mapper.createArrayNode();
    extensions.forEach(ext -> ext.views()
            .forEach(v -> node.add(mapper.createObjectNode()
                                           .put("id", v.id())
                                           .put("category", v.category().label())
                                           .put("label", v.label())
                                           .put("icon", v.iconId()))));
    return node;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:12,代码来源:UiViewListCommand.java

示例13: handleTabbedFields

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredFields, Map<Field, JsonNode> nodes) {
	Predicate<? super Field> checkTabAnnotation = field -> field.isAnnotationPresent(Tab.class);

	Comparator<? super Field> tabIndexComparator = (field1, field2) -> Integer
			.compare(field1.getAnnotation(Tab.class).index(), field2.getAnnotation(Tab.class).index());

	Comparator<? super Field> fieldIndexComparator = (entry1, entry2) -> {
		Index field1Index = entry1.getAnnotation(Index.class);
		Index field2Index = entry2.getAnnotation(Index.class);
		return Integer.compare((field1Index != null ? field1Index.value() : Integer.MAX_VALUE),
				field2Index != null ? field2Index.value() : Integer.MAX_VALUE);
	};

	Map<String, List<JsonNode>> groupedFieldsByTab = new LinkedHashMap<>();

	Arrays.stream(declaredFields).filter(checkTabAnnotation).sorted(fieldIndexComparator).sorted(tabIndexComparator)
			.forEach(field -> groupFieldsByTab(nodes, field, groupedFieldsByTab));

	ArrayNode tabs = mapper.createArrayNode();

	groupedFieldsByTab.entrySet().stream().forEachOrdered(tabElements -> {
		ObjectNode tabNode = mapper.createObjectNode();
		tabNode.put(KEY_TITLE, tabElements.getKey());
		ArrayNode tabItems = mapper.createArrayNode();
		tabElements.getValue().stream().forEach(tabItems::add);
		tabNode.set(KEY_ITEMS, tabItems);
		tabs.add(tabNode);
	});
	if (tabs.size() > 0) {
		ObjectNode tabsNode = mapper.createObjectNode();
		tabsNode.put(KEY_TYPE, KEY_TABS);
		tabsNode.set(KEY_TABS, tabs);
		return tabsNode;
	}
	return null;

}
 
开发者ID:JsonSchema-JavaUI,项目名称:sf-java-ui,代码行数:38,代码来源:UiFormSchemaGenerator.java

示例14: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
 * Produces a JSON array of intent events.
 *
 * @param intentEvents the intent events with the data
 * @return JSON array with the intent events
 */
private JsonNode json(List<IntentEvent> intentEvents) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    for (IntentEvent event : intentEvents) {
        result.add(json(mapper, event));
    }
    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:16,代码来源:IntentEventsListCommand.java

示例15: json

import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private JsonNode json(Iterable<TopologyCluster> clusters) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    clusters.spliterator()
            .forEachRemaining(cluster ->
                    result.add(jsonForEntity(cluster, TopologyCluster.class)));

    return result;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:11,代码来源:ClustersListCommand.java


注:本文中的com.fasterxml.jackson.databind.ObjectMapper.createArrayNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。