當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonWriter.beginObject方法代碼示例

本文整理匯總了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);
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:17,代碼來源:ObjectTypeAdapter.java

示例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();
}
 
開發者ID:Twister915,項目名稱:pl,代碼行數:18,代碼來源:LocationTypeAdapter.java

示例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();
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:ReflectiveTypeAdapterFactory.java

示例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();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:RLESparseResourceAllocation.java

示例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");
  }
}
 
開發者ID:synthetichealth,項目名稱:synthea_java,代碼行數:28,代碼來源:ReportExporter.java

示例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);
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaCore,代碼行數:32,代碼來源:MessagePart.java

示例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();
}
 
開發者ID:sap-nocops,項目名稱:Jerkoff,代碼行數:9,代碼來源:ObjectTypeAdapterFactory.java

示例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();
}
 
開發者ID:WoutDev,項目名稱:Mega-Walls,代碼行數:13,代碼來源:LocationAdapter.java

示例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();
}
 
開發者ID:LightSun,項目名稱:data-mediator,代碼行數:12,代碼來源:SparseArrayTypeAdapter.java

示例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);
	}
}
 
開發者ID:Slaymd,項目名稱:CaulCrafting,代碼行數:39,代碼來源:MessagePart.java

示例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();
}
 
開發者ID:Slaymd,項目名稱:CaulCrafting,代碼行數:10,代碼來源:TextualComponent.java

示例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();
}
 
開發者ID:iLefty,項目名稱:mcClans,代碼行數:39,代碼來源:JsonSaver.java

示例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();
}
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:33,代碼來源:FpcCodecUtils.java

示例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();
}
 
開發者ID:rockscript,項目名稱:rockscript,代碼行數:10,代碼來源:PolymorphicTypeNameStrategy.java

示例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());
}
 
開發者ID:yandex,項目名稱:graphouse,代碼行數:31,代碼來源:MetricDataRowCallbackHandlerTest.java


注:本文中的com.google.gson.stream.JsonWriter.beginObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。