本文整理匯總了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();
}
}