本文整理汇总了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);
}
}
示例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);
}
示例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;
}