本文整理汇总了Java中javax.json.stream.JsonGenerator.writeNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeNull方法的具体用法?Java JsonGenerator.writeNull怎么用?Java JsonGenerator.writeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.stream.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeNull方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commitFact
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
public void commitFact(final Fact f, final Change.Type ct, final JsonGenerator json, final boolean recursive) {
json
.write("key", f.key)
.write("createdAt", context.formatJS(f.createdAt));
switch(ct) {
case DELETE: {
json.write("deleted", true);
break;
}
case INSERT: {
json.write("version", f.version);
if (!recursive || f.previousVersion == null) {
json.writeNull("previousVersion");
} else {
json.writeStartObject("previousVersion");
commitFact(f.previousVersion, ct, json, false);
json.writeEnd();
}
break;
}
default:
throw new RuntimeException("Unknown change type: " + ct);
}
}
示例2: serializeItem
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
protected void serializeItem(Object item, JsonGenerator generator, SerializationContext ctx, JsonBindingModel model) {
if (item == null) {
generator.writeNull();
return;
}
Class<?> itemClass = item.getClass();
JsonbSerializer<?> serializer = getValueSerializer(itemClass);
if (serializer == null) {
serializer = new SerializerBuilder(((Marshaller)ctx).getJsonbContext()).withObjectClass(itemClass).withWrapper(this).withModel(model).build();
addValueSerializer(serializer, itemClass);
}
serializerCaptor(serializer, item, generator, ctx);
}
示例3: serialize
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void serialize(OptionalLong obj, JsonGenerator generator, Marshaller marshaller) {
if (obj.isPresent()) {
generator.write(obj.getAsLong());
} else if (model.getCustomization().isNillable()) {
generator.writeNull();
}
}
示例4: marshallProperty
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void marshallProperty(T object, JsonGenerator generator, SerializationContext ctx, PropertyModel propertyModel) {
Marshaller marshaller = (Marshaller) ctx;
if (propertyModel.isReadable()) {
final Object propertyValue = propertyModel.getValue(object);
if (propertyValue == null || isEmptyOptional(propertyValue)) {
if (propertyModel.getCustomization().isNillable()) {
generator.writeNull(propertyModel.getWriteName());
}
return;
}
generator.writeKey(propertyModel.getWriteName());
final JsonbSerializer<?> propertyCachedSerializer = propertyModel.getPropertySerializer();
if (propertyCachedSerializer != null) {
serializerCaptor(propertyCachedSerializer, propertyValue, generator, ctx);
return;
}
Optional<Type> runtimeTypeOptional = ReflectionUtils.resolveOptionalType(this, propertyModel.getType());
Type genericType = runtimeTypeOptional.orElse(null);
final JsonbSerializer<?> serializer = new SerializerBuilder(marshaller.getJsonbContext())
.withWrapper(this)
.withObjectClass(propertyValue.getClass()).withModel(propertyModel)
.withType(genericType).build();
serializerCaptor(serializer, propertyValue, generator, ctx);
}
}
示例5: serializeInternal
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void serializeInternal(T obj, JsonGenerator generator, SerializationContext ctx) {
for (Map.Entry<?,?> entry : obj.entrySet()) {
final String keysString = String.valueOf(entry.getKey());
final Object value = entry.getValue();
if (value == null) {
generator.writeNull(keysString);
return;
}
generator.writeKey(keysString);
serializeItem(value, generator, ctx, containerModel);
}
}
示例6: serialize
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void serialize(OptionalInt obj, JsonGenerator generator, Marshaller marshaller) {
if (obj.isPresent()) {
generator.write(obj.getAsInt());
} else if (model.getCustomization().isNillable()) {
generator.writeNull();
}
}
示例7: serialize
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(T obj, JsonGenerator generator, SerializationContext ctx) {
JsonbContext jsonbContext = ((ProcessingContext) ctx).getJsonbContext();
if (obj == null || !obj.isPresent()) {
if (!wrapperModel.getCustomization().isNillable()) {
return;
}
generator.writeNull();
return;
}
Object optionalValue = obj.get();
final JsonbSerializer<?> serializer = new SerializerBuilder(jsonbContext).withObjectClass(optionalValue.getClass())
.withType(optionalValueType).withWrapper(wrapper).withModel(wrapperModel).build();
serialCaptor(serializer, optionalValue, generator, ctx);
}
示例8: serialize
import javax.json.stream.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void serialize(OptionalDouble obj, JsonGenerator generator, Marshaller marshaller) {
if (obj.isPresent()) {
generator.write(obj.getAsDouble());
} else if (model.getCustomization().isNillable()) {
generator.writeNull();
}
}