本文整理汇总了Java中com.google.gson.stream.JsonWriter.name方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.name方法的具体用法?Java JsonWriter.name怎么用?Java JsonWriter.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例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包/类
@Override
public void write(JsonWriter out, ItemStack value) throws IOException {
if (value != null) {
out.beginObject();
out.name("id").value(value.getTypeId());
if (value.getDurability() > 0)
out.name("damage").value(value.getDurability());
if (value.getAmount() > 0)
out.name("amount").value(value.getAmount());
if (value.getItemMeta() != null) {
out.name("meta");
metaAdapter.write(out, value.getItemMeta());
}
out.endObject();
} else {
out.nullValue();
}
}
示例4: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void write(JsonWriter out, Calendar value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
out.beginObject();
out.name("year");
out.value((long) value.get(1));
out.name("month");
out.value((long) value.get(2));
out.name(DAY_OF_MONTH);
out.value((long) value.get(5));
out.name(HOUR_OF_DAY);
out.value((long) value.get(11));
out.name("minute");
out.value((long) value.get(12));
out.name(SECOND);
out.value((long) value.get(13));
out.endObject();
}
示例5: encode
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
private String encode(Object instance)
throws IOException {
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new JsonWriter(stringWriter);
try {
Class<?> type = instance.getClass();
writer.beginObject();
writer.name(type.getName());
gson.toJson(instance, type, writer);
writer.endObject();
return stringWriter.toString();
} finally {
writer.close();
}
}
示例6: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, GsonProperty property, Object value) throws IOException {
final Class<?> simpleType = property.getType();
out.beginObject();
if(value != null) {
final SparseArray sa = (SparseArray) value;
if(simpleType.isPrimitive() || isBoxedClass(simpleType)){
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
writePrimitiveOrItsBox(out, simpleType, sa.valueAt(i));
}
}else {
TypeAdapter adapter = getTypeAdapter(simpleType);
for (int size = sa.size(), i = size - 1; i >= 0; i--) {
out.name(sa.keyAt(i) + "");
adapter.write(out, sa.valueAt(i));
}
}
}
out.endObject();
}
示例7: 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();
}
}
示例8: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, GUISignature value) throws IOException {
if (value != null) {
Map<Integer, Integer> hashCodeMap = new HashMap<>();
Map<Integer, Object> contents = new HashMap<>();
Map<Integer, ItemStack> itemMap = value.getContents();
for (Map.Entry<Integer, ItemStack> entry : itemMap.entrySet()) {
contents.put(entry.getKey(), value(contents, entry.getValue(), hashCodeMap));
}
out.beginObject();
out.name("type").value(value.getType().name());
out.name("title").value(value.getTitle());
out.name("size").value(value.getSize());
out.name("data");
mapAdapter.write(out, contents);
out.name("handlerIndexes");
collectionAdapter.write(out, value.getHandlerIndexes());
out.endObject();
} else {
out.nullValue();
}
}
示例9: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(JsonWriter out, Calendar value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
out.beginObject();
out.name(YEAR);
out.value(value.get(Calendar.YEAR));
out.name(MONTH);
out.value(value.get(Calendar.MONTH));
out.name(DAY_OF_MONTH);
out.value(value.get(Calendar.DAY_OF_MONTH));
out.name(HOUR_OF_DAY);
out.value(value.get(Calendar.HOUR_OF_DAY));
out.name(MINUTE);
out.value(value.get(Calendar.MINUTE));
out.name(SECOND);
out.value(value.get(Calendar.SECOND));
out.endObject();
}
示例10: writeJson
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
public void writeJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.beginObject();
jsonWriter.name("max");
max.writeJson(jsonWriter);
jsonWriter.name("min");
min.writeJson(jsonWriter);
jsonWriter.endObject();
}
示例11: write
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void write(
final JsonWriter out,
final T value
) throws IOException {
// support null objects
if (value == null) {
out.nullValue();
return;
}
// assert begin of object
out.beginObject();
// get discriminator
Object discriminator = fieldAccess.get(value, DISCRIMINATOR_FIELD_NAME);
// write discriminator
out.name(DISCRIMINATOR_FIELD_NAME);
((TypeAdapter<Object>) discriminatorTypeAdapter).write(out, discriminator);
// get corresponding union field info
UnionMemberInfo unionMemberInfo = memberInfoMap.get(discriminator.toString());
// write field
out.name(unionMemberInfo.fieldName);
((TypeAdapter<Object>) unionMemberInfo.typeAdapter).write(
out,
fieldAccess.get(value, unionMemberInfo.fieldName)
);
// assert end of object
out.endObject();
}
示例12: testWr
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Test
public void testWr() {
try {
Writer wr = new StringWriter();
JsonWriter out = new JsonWriter(wr);
out.beginObject();
out.name("class");
out.value(this.getClass().getName());
out.endObject();
out.close();
LOG.info("json: " + wr.toString());
} catch (Exception e) {
LOG.error(e);
}
}
示例13: serialize
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void serialize(JsonWriter writer) throws IOException {
writer.beginObject();
writer.name("value");
writer.value(getAsString());
writer.endObject();
}
示例14: serialize
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void serialize(JsonWriter writer) throws IOException {
writer.beginObject();
writer.name("bind");
if(bind != null)
writer.value(bind.getKeyCode());
else
writer.value(-1);
writer.endObject();
}
示例15: serialize
import com.google.gson.stream.JsonWriter; //导入方法依赖的package包/类
@Override
public void serialize(JsonWriter writer) throws IOException {
writer.beginObject();
writer.name("enabled");
writer.value(enabled);
writer.name("keyword");
writer.value(keyword);
writer.name("type");
writer.value(type.name());
writer.name("trigger");
writer.value(trigger.name());
writer.name("delay");
writer.value(getDelay());
writer.name("messages");
writer.beginArray();
for(String msg : messages) {
writer.value(msg);
}
writer.endArray();
writer.endObject();
}