本文整理汇总了Java中com.google.gson.stream.JsonWriter.beginObject方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.beginObject方法的具体用法?Java JsonWriter.beginObject怎么用?Java JsonWriter.beginObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.beginObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override public void write(JsonWriter out, Object value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
TypeAdapter<Object> typeAdapter = (TypeAdapter<Object>) gson.getAdapter(value.getClass());
if (typeAdapter instanceof ObjectTypeAdapter) {
out.beginObject();
out.endObject();
return;
}
typeAdapter.write(out, value);
}
示例2: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, Location value) throws IOException {
out.beginObject();
out.name(WORLD_KEY);
out.value(value.getWorld().getUID().toString());
out.name(X_KEY);
out.value(value.getX());
out.name(Y_KEY);
out.value(value.getY());
out.name(Z_KEY);
out.value(value.getZ());
out.name(PITCH);
out.value(value.getPitch());
out.name(YAW);
out.value(value.getYaw());
out.endObject();
}
示例3: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void write(JsonWriter out, T value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
out.beginObject();
try {
for (BoundField boundField : this.boundFields.values()) {
if (boundField.serialized) {
out.name(boundField.name);
boundField.write(out, value);
}
}
out.endObject();
} catch (IllegalAccessException e) {
throw new AssertionError();
}
}
示例4: toMemJSONString
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
* Returns the JSON string representation of the current resources allocated
* over time
*
* @return the JSON string representation of the current resources allocated
* over time
*/
public String toMemJSONString() {
StringWriter json = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(json);
readLock.lock();
try {
jsonWriter.beginObject();
// jsonWriter.name("timestamp").value("resource");
for (Map.Entry<Long, Resource> r : cumulativeCapacity.entrySet()) {
jsonWriter.name(r.getKey().toString()).value(r.getValue().toString());
}
jsonWriter.endObject();
jsonWriter.close();
return json.toString();
} catch (IOException e) {
// This should not happen
return "";
} finally {
readLock.unlock();
}
}
示例5: export
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public static void export(Generator generator) {
if (generator == null || generator.database == null) {
return;
}
try (Connection connection = generator.database.getConnection()) {
File outDirectory = Exporter.getOutputFolder("statistics", null);
String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
Path outFilePath = outDirectory.toPath().resolve("statistics-" + timeStamp + ".json");
JsonWriter writer = new JsonWriter(new FileWriter(outFilePath.toFile()));
writer.setIndent(" ");
writer.beginObject(); // top-level
reportParameters(writer);
processOutcomes(connection, writer);
processAccess(connection, writer);
processCosts(connection, writer);
writer.endObject(); // top-level
writer.close();
} catch (IOException | SQLException e) {
e.printStackTrace();
throw new RuntimeException("error exporting statistics");
}
}
示例6: writeJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void writeJson(JsonWriter json) {
try {
json.beginObject();
text.writeJson(json);
json.name("color").value(color.name().toLowerCase());
for (final ChatColor style : styles) {
json.name(stylesToNames.get(style)).value(true);
}
if (clickActionName != null && clickActionData != null) {
json.name("clickEvent").beginObject().name("action").value(clickActionName).name("value").value(clickActionData).endObject();
}
if (hoverActionName != null && hoverActionData != null) {
json.name("hoverEvent").beginObject().name("action").value(hoverActionName).name("value");
hoverActionData.writeJson(json);
json.endObject();
}
if (insertionData != null) {
json.name("insertion").value(insertionData);
}
if (translationReplacements.size() > 0 && text != null && TextualComponent.isTranslatableText(text)) {
json.name("with").beginArray();
for (JsonRepresentedObject obj : translationReplacements) {
obj.writeJson(json);
}
json.endArray();
}
json.endObject();
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
}
}
示例7: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void write(JsonWriter out, T value) throws IOException {
out.beginObject();
out.name("class");
out.value(value.getClass().getName());
out.name("value");
delegate.write(out, value);
out.endObject();
}
示例8: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, Location location) throws IOException
{
out.beginObject();
out.name("x").value(location == null ? 30000001 : location.getX());
out.name("y").value(location == null ? 30000001 : location.getY());
out.name("z").value(location == null ? 30000001 : location.getZ());
out.name("pitch").value(location == null ? 30000001 : location.getPitch());
out.name("yaw").value(location == null ? 30000001 : location.getYaw());
out.name("world").value((location == null || location.getWorld() == null) ? "" : location.getWorld().getName());
out.endObject();
}
示例9: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, SparseArray<T> value) throws IOException {
out.beginObject();
if(value != null) {
for (int size = value.size(), i = size - 1; i >= 0; i--) {
out.name(value.keyAt(i) + "");
mAdapter.write(out, value.valueAt(i));
}
}
out.endObject();
}
示例10: writeJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void writeJson(JsonWriter json) {
try {
json.beginObject();
text.writeJson(json);
json.name("color").value(color.name().toLowerCase());
for (final ChatColor style : styles) {
json.name(stylesToNames.get(style)).value(true);
}
if (clickActionName != null && clickActionData != null) {
json.name("clickEvent")
.beginObject()
.name("action").value(clickActionName)
.name("value").value(clickActionData)
.endObject();
}
if (hoverActionName != null && hoverActionData != null) {
json.name("hoverEvent")
.beginObject()
.name("action").value(hoverActionName)
.name("value");
hoverActionData.writeJson(json);
json.endObject();
}
if (insertionData != null) {
json.name("insertion").value(insertionData);
}
if (translationReplacements.size() > 0 && text != null && TextualComponent.isTranslatableText(text)) {
json.name("with").beginArray();
for (JsonRepresentedObject obj : translationReplacements) {
obj.writeJson(json);
}
json.endArray();
}
json.endObject();
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
}
}
示例11: writeJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.name(getKey());
writer.beginObject();
for (Map.Entry<String, String> jsonPair : _value.entrySet()) {
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
}
writer.endObject();
}
示例12: saveStarted
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
protected void saveStarted() throws Exception {
File clansFile = new File(saveDataFolder, "clans.json");
File clanPlayersFile = new File(saveDataFolder, "clanPlayers.json");
File ranksFile = new File(saveDataFolder, "ranks.json");
File alliesFile = new File(saveDataFolder, "allies.json");
File tempClansFile = new File(tempDataFolder, "clans.json");
File tempClanPlayersFile = new File(tempDataFolder, "clanPlayers.json");
File tempRanksFile = new File(tempDataFolder, "ranks.json");
File tempAlliesFile = new File(tempDataFolder, "allies.json");
FileUtils.copyFile(clansFile, tempClansFile);
FileUtils.copyFile(clanPlayersFile, tempClanPlayersFile);
FileUtils.copyFile(ranksFile, tempRanksFile);
FileUtils.copyFile(alliesFile, tempAlliesFile);
clansWriter = new JsonWriter(new FileWriter(clansFile));
clanPlayersWriter = new JsonWriter(new FileWriter(clanPlayersFile));
ranksWriter = new JsonWriter(new FileWriter(ranksFile));
alliesWriter = new JsonWriter(new FileWriter(alliesFile));
clansWriter.beginObject();
clansWriter.name("dataVersion").value(DatabaseHandler.CURRENT_DATA_VERSION);
clansWriter.name("list").beginArray();
clanPlayersWriter.beginObject();
clanPlayersWriter.name("dataVersion").value(DatabaseHandler.CURRENT_DATA_VERSION);
clanPlayersWriter.name("list").beginArray();
ranksWriter.beginObject();
ranksWriter.name("dataVersion").value(DatabaseHandler.CURRENT_DATA_VERSION);
ranksWriter.name("list").beginArray();
alliesWriter.beginObject();
alliesWriter.name("dataVersion").value(DatabaseHandler.CURRENT_DATA_VERSION);
alliesWriter.name("list").beginArray();
}
示例13: jsonStringFromConfigureOutput
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
/**
* Convert ConfigureOutput object to JSON String
* @param object - ConfigureOutput object
* @return - JSON string of ConfigureOutput
*/
public final String jsonStringFromConfigureOutput(DataObject object) {
final Writer writer = new StringWriter();
JsonWriter jsonWriter = JsonWriterFactory.createJsonWriter(writer);
final NormalizedNodeStreamWriter domWriter = JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.create(context), CONFIGURE_OUTPUT_PATH, CONFIGURE_OUTPUT_PATH.getLastComponent().getNamespace(), jsonWriter);
RestconfNormalizedNodeWriter restConfWriter = null;
try {
jsonWriter.beginObject();
restConfWriter = (RestconfNormalizedNodeWriter) RestconfDelegatingNormalizedNodeWriter.forStreamWriter(domWriter);
jsonWriter.name("output");
for (DataContainerChild<? extends org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument, ?> child : codecRegistry.toNormalizedNodeRpcData((DataContainer)object).getValue()) {
try {
restConfWriter.write(child);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e2){
e2.printStackTrace();
}
}
jsonWriter.endObject();
restConfWriter.flush();
jsonWriter.flush();
} catch (IOException e1) {
e1.printStackTrace();
}
return writer.toString();
}
示例14: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, String typeName, FieldsWriter fieldsWriter) throws Exception {
out.beginObject();
out.name(typeName);
out.beginObject();
fieldsWriter.writeFields(typeName);
out.endObject();
out.endObject();
}
示例15: testHandler
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Test
public void testHandler() throws Exception {
MockResultSet resultSet = new MockResultSet("data");
resultSet.addColumn("metric", new String[]{"name1", "name1", "name2", "name2"});
resultSet.addColumn("ts", new Integer[]{100, 160, 160, 220});
resultSet.addColumn("value", new Double[]{33.33, 42.0, 32.0, 77.7});
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.beginObject();
MetricDataService.MetricDataRowCallbackHandler handler = new MetricDataService.MetricDataRowCallbackHandler(
jsonWriter, 100, 280, 60
);
while (resultSet.next()) {
handler.processRow(resultSet);
}
handler.finish();
jsonWriter.endObject();
JsonObject expected = new JsonObject();
expected.add("name1", createMetric(100, 280, 60, 33.33, 42.0, Double.NaN));
expected.add("name2", createMetric(100, 280, 60, Double.NaN, 32.0, 77.7));
Assert.assertEquals(expected.toString(), stringWriter.toString());
}