当前位置: 首页>>代码示例>>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;未经允许,请勿转载。