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


Java JsonObject.size方法代码示例

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


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

示例1: _execute

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
public void _execute() throws Exception {

  setSplitSize(300);

  // Get Workspace in JSON format from WCS API
  JsonObject jsonWCSPayload = getConvWorkspace();

  if (jsonWCSPayload.size() > 0) {
    // Parse Intents and store it in Intents TreeMap
    Map<String, TreeSet<String>> uniqueBotOutputIntents = parseWCSIntents(jsonWCSPayload);

    // Parse Intents and store it in Entities TreeMap
    Map<String, TreeSet<String>> uniqueBotOutputEntities = parseWCSEntities(jsonWCSPayload);

    // Parse Intents and store it in Dialogs TreeMap
    Map<String, TreeSet<String>> uniqueBotOutputDialogs = parseWCSDialogs(jsonWCSPayload);

    int splitSize = getSplitSize();
    // Create bundles on GP and upload resource string to bundles
    createBundles(uniqueBotOutputIntents, uniqueBotOutputEntities, uniqueBotOutputDialogs, splitSize, jsonWCSPayload);
  }

}
 
开发者ID:IBM-Cloud,项目名称:gp-watson-conversation,代码行数:25,代码来源:WCS_To_GP.java

示例2: convertToEventArrayForDefaultMapping

import com.google.gson.JsonObject; //导入方法依赖的package包/类
private Event[] convertToEventArrayForDefaultMapping(Object eventObject) {
    Gson gson = new Gson();
    JsonObject[] eventObjects = gson.fromJson(eventObject.toString(), JsonObject[].class);
    Event[] events = new Event[eventObjects.length];
    int index = 0;
    JsonObject eventObj = null;
    for (JsonObject jsonEvent : eventObjects) {
        if (jsonEvent.has(DEFAULT_JSON_EVENT_IDENTIFIER)) {
            eventObj = jsonEvent.get(DEFAULT_JSON_EVENT_IDENTIFIER).getAsJsonObject();
            if (failOnMissingAttribute && eventObj.size() < streamAttributes.size()) {
                log.error("Json message " + eventObj.toString() + " contains missing attributes. " +
                        "Hence dropping the message.");
                continue;
            }
        } else {
            log.error("Default json message " + eventObj.toString()
                    + " in the array does not have the valid event identifier \"event\". " +
                    "Hence dropping the message.");
            continue;
        }
        Event event = new Event(streamAttributes.size());
        Object[] data = event.getData();


        int position = 0;
        for (Attribute attribute : streamAttributes) {
            String attributeName = attribute.getName();
            Attribute.Type type = attribute.getType();
            String attributeValue = eventObj.get(attributeName).getAsString();
            if (attributeValue == null) {
                data[position++] = null;
            } else {
                data[position++] = attributeConverter.getPropertyValue(
                        attributeValue, type);
            }
        }
        events[index++] = event;
    }
    return Arrays.copyOfRange(events, 0, index);
}
 
开发者ID:wso2-extensions,项目名称:siddhi-map-json,代码行数:41,代码来源:JsonSourceMapper.java

示例3: matchesSafely

import com.google.gson.JsonObject; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(
	JsonObject jsonObject, Description description) {

	Map<String, Consumer<Description>> mismatchedKeys = new HashMap<>();

	_entryMatchers.forEach(
		(key, value) -> {
			JsonElement jsonElement = jsonObject.get(key);

			if (!value.matches(jsonElement)) {
				mismatchedKeys.put(
					key,
					consumerDescription -> value.describeMismatch(
						jsonElement, consumerDescription));
			}
		});

	Set<String> keys = _entryMatchers.keySet();

	if (!mismatchedKeys.isEmpty()) {
		description.appendText("was a JSON object ");

		describeNestedMismatches(
			keys, description, mismatchedKeys,
			(text, innerDescription) -> innerDescription.appendText(text));

		return false;
	}

	if (_strictMode && (jsonObject.size() > _entryMatchers.size())) {
		Set<String> jsonObjectKeys = new HashSet<>(jsonObject.keySet());

		jsonObjectKeys.removeAll(keys);

		Stream<String> stream = jsonObjectKeys.stream();

		String extraKeys = stream.collect(Collectors.joining(", "));

		description.appendText(
			"was a JSON object "
		).appendText(
			"with more fields than validated. "
		).appendText(
			"Extra keys: "
		).appendText(
			extraKeys
		);

		return false;
	}

	return true;
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:55,代码来源:IsJsonObject.java


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