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


Java JsonGenerator.writeNull方法代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:moforw,項目名稱:albaum,代碼行數:26,代碼來源:Log.java

示例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);
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:14,代碼來源:AbstractContainerSerializer.java

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

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

示例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);
    }
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:15,代碼來源:MapSerializer.java

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

示例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);
}
 
開發者ID:eclipse,項目名稱:yasson,代碼行數:16,代碼來源:OptionalObjectSerializer.java

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


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