當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。