本文整理汇总了Java中com.google.gson.JsonArray.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.forEach方法的具体用法?Java JsonArray.forEach怎么用?Java JsonArray.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonArray
的用法示例。
在下文中一共展示了JsonArray.forEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public void fromJson(final JsonElement json)
{
if (!json.isJsonArray())
throw new IllegalArgumentException("json is not an array");
final JsonArray array = json.getAsJsonArray();
array.forEach((dt) ->
{
if (dt.isJsonObject())
{
final JsonObject dtObj = dt.getAsJsonObject();
final String key = dtObj.get("key").getAsString();
final String type = dtObj.get("type").getAsString();
final DataType<?> dataType = DataManager.typesValues.get(type);
if (dataType != null)
{
final Object value = dataType.fromJson(dtObj.get("value"));
this.setOrAddInternalValue(dataType, key, value);
}
}
});
}
示例2: writeMap
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private void writeMap(String key, JsonObject json) {
if (json.has("class")) {
String clazz = json.get("class").getAsString();
if ("array".equals(clazz)) {
String type = json.get("type").getAsString();
JsonArray elements = json.get("elements").getAsJsonArray();
writer.beginList(key, type);
elements.forEach(this::writeValue);
writer.endList();
} else {
writer.beginObject(key, clazz);
json.entrySet().forEach(e -> {
if (!e.getKey().equals("class")) {
writeProperty(e.getKey(), e.getValue());
}
});
writer.endObject();
}
} else {
writer.beginMap(key);
json.entrySet().forEach(e -> writeProperty(e.getKey(), e.getValue()));
writer.endMap();
}
}
示例3: deserialize
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public ControllableComponent deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonArray arr = json.getAsJsonArray();
ControllableComponent control = new ControllableComponent();
Level level = Level.deserializing();
arr.forEach((element) -> {
String str = element.getAsString();
if (level.getCommands().containsKey(str)) {
control.commands.add(level.getCommands().get(str));
} else {
throw new JsonParseException("Could not find command " + str);
}
});
return control;
}
示例4: setDefaultValues
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Report setDefaultValues(Report report, JsonObject jsonReport) {
JsonElement name = jsonReport.get("name");
JsonArray entries = jsonReport.get("entries").getAsJsonArray();
JsonArray subReports = jsonReport.get("subReports").getAsJsonArray();
report.setName(prepareGsonParser().fromJson(name, StringKey.class));
entries.forEach(subEntry -> {
Entry entry = prepareGsonParser().fromJson(subEntry, Entry.class);
report.getEntries().add(entry);
});
subReports.forEach(subReport -> {
Report subReportEntry = prepareGsonParser().fromJson(subReport, Report.class);
report.getSubReports().add(subReportEntry);
});
return report;
}
示例5: fromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static List<Code> fromJson(JsonArray jsonCodes) {
List<Code> codes = new ArrayList<>();
jsonCodes.forEach(item -> {
codes.add(new Code((JsonObject) item));
});
return codes;
}
示例6: dataFromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
protected void dataFromJson(final JsonElement data)
{
if (!data.isJsonArray())
throw new IllegalArgumentException("json is not an array");
final JsonArray array = data.getAsJsonArray();
array.forEach((trans) ->
{
if (trans.isJsonObject())
{
final JsonObject transObj = trans.getAsJsonObject();
final String key = transObj.get("key").getAsString();
this.addKey(key);
final JsonArray translations = transObj.get("translations").getAsJsonArray();
translations.forEach((elem) ->
{
if (elem.isJsonObject())
{
final JsonObject elemObj = elem.getAsJsonObject();
final String lang = elemObj.get("lang").getAsString();
this.addLanguage(lang);
this.setTranslation(key, lang, elemObj.get("value").getAsString());
}
});
}
});
}
示例7: buildFromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public Map<String, Object> buildFromJson(Map<String, JsonElement> configuration) throws Exception
{
if (configuration.containsKey("entities"))
{
JsonArray entityTypesJson = configuration.get("entities").getAsJsonArray();
entityTypesJson.forEach(element -> this.addEntityType(EntityType.valueOf(element.getAsString().toUpperCase())));
}
return this.build();
}
示例8: buildFromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public Map<String, Object> buildFromJson(Map<String, JsonElement> configuration) throws Exception
{
if (configuration.containsKey("blacklist"))
{
JsonArray blacklistJson = configuration.get("blacklist").getAsJsonArray();
blacklistJson.forEach(jsonElement -> this.blacklistPotionEffect(PotionEffectType.getByName(jsonElement.getAsString())));
}
return this.build();
}
示例9: buildFromJson
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public Map<String, Object> buildFromJson(Map<String, JsonElement> configuration) throws Exception
{
if (configuration.containsKey("blocks"))
{
JsonArray blocksJson = configuration.get("blocks").getAsJsonArray();
blocksJson.forEach(element -> this.blocks.add(Material.matchMaterial(element.getAsString())));
}
if (configuration.containsKey("damages"))
this.setDamages(configuration.get("damages").getAsDouble());
return this.build();
}
示例10: getLicensedModNames
import com.google.gson.JsonArray; //导入方法依赖的package包/类
/**
* Retrieves a list with the names of all mods licensed to the user
*
* @return {@code String array} of the mod names
*/
public static List<String> getLicensedModNames() {
JsonObject json = new Gson().fromJson(getSafe(getUserLicensedProductNamesURL()), JsonObject.class);
JsonArray arr = json.get("data").getAsJsonArray();
List<String> list = new ArrayList<String>();
arr.forEach((jsonElement) -> list.add(jsonElement.getAsString()));
return list;
}
示例11: parseExecutionReport
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Report parseExecutionReport(JsonObject jsonReport, JsonDeserializationContext context){
ExecutionReport executionReport = new ExecutionReport();
JsonArray testSuiteReportsJson = jsonReport.get("testSuiteReports").getAsJsonArray();
testSuiteReportsJson.forEach(suite -> {
Report testSuiteReport = prepareGsonParser().fromJson(suite, TestSuiteReport.class);
executionReport.getTestSuiteReports().add((TestSuiteReport) testSuiteReport);
});
return setDefaultValues(executionReport, jsonReport);
}
示例12: parseTestSuiteReport
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Report parseTestSuiteReport(JsonObject jsonReport){
TestSuiteReport testSuiteReport = new TestSuiteReport();
JsonArray testClassReportsJson = jsonReport.get("testClassReports").getAsJsonArray();
testClassReportsJson.forEach(testClass -> {
Report testClassReport = prepareGsonParser().fromJson(testClass, TestClassReport.class);
testSuiteReport.getTestClassReports().add((TestClassReport) testClassReport);
});
setConfiguration(testSuiteReport, jsonReport);
setStartAndStop(testSuiteReport, jsonReport);
return setDefaultValues(testSuiteReport, jsonReport);
}
示例13: parseTestClassReport
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private Report parseTestClassReport(JsonObject jsonReport){
TestClassReport testClassReport = new TestClassReport();
JsonArray testMethodReportsJson = jsonReport.get("testMethodReports").getAsJsonArray();
testMethodReportsJson.forEach(testMethod -> {
Report testMethodReport = prepareGsonParser().fromJson(testMethod, TestMethodReport.class);
testClassReport.getTestMethodReports().add((TestMethodReport) testMethodReport);
});
setConfiguration(testClassReport, jsonReport);
setStartAndStop(testClassReport, jsonReport);
return setDefaultValues(testClassReport, jsonReport);
}
示例14: encodeCanonicalArray
import com.google.gson.JsonArray; //导入方法依赖的package包/类
private static void encodeCanonicalArray(JsonArray array, JsonWriterUnchecked writer) throws IOException {
writer.beginArray();
array.forEach(el -> encodeCanonicalElement(el, writer));
writer.endArray();
}
示例15: deserialize
import com.google.gson.JsonArray; //导入方法依赖的package包/类
@Override
public Layout deserialize(JsonElement json, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
String name = obj.get("_type").getAsString();
JsonArray children = obj.get("_children").getAsJsonArray();
Layout layout = Components.getDefault().createComponent(name).flatMap(TypeUtils.optionalCast(Layout.class))
.orElseThrow(() -> new JsonParseException("Can't find layout name " + name));
if (layout instanceof Sourced) {
Sourced sourcedLayout = (Sourced) layout;
for (int i = 0; i > Integer.MIN_VALUE; i++) {
String prop = "_source" + i;
if (obj.has(prop)) {
String uri = obj.get(prop).getAsString();
Optional<? extends DataSource<?>> source = Sources.getDefault().get(uri);
try {
if (source.isPresent()) {
sourcedLayout.addSource(source.get());
} else {
sourcedRestorer.addDestroyedSourcesForAllDataTypes(sourcedLayout, uri);
}
} catch (IncompatibleSourceException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Couldn't load source", e);
sourcedRestorer.addDestroyedSourcesForAllDataTypes(sourcedLayout, uri);
}
} else {
break;
}
}
}
JsonElement title = obj.get("_title");
if (title != null) {
layout.setTitle(title.getAsString());
}
children.forEach(child -> {
String childName = child.getAsJsonObject().get("_type").getAsString();
Optional<Type> childType = Components.getDefault().javaTypeFor(childName);
childType.map(t -> context.deserialize(child, t))
.flatMap(TypeUtils.optionalCast(Component.class))
.ifPresent(layout::addChild);
});
return layout;
}