Java Code Examples for org.bson.BsonWriter#writeNull()
The following examples show how to use
org.bson.BsonWriter#writeNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityEncoder.java From morphia with Apache License 2.0 | 6 votes |
private <S> void encodeValue(final BsonWriter writer, final EncoderContext encoderContext, final FieldModel<S> model, final S propertyValue) { if (model.shouldSerialize(propertyValue)) { writer.writeName(model.getMappedName()); if (propertyValue == null) { writer.writeNull(); } else { try { encoderContext.encodeWithChildContext(model.getCachedCodec(), writer, propertyValue); } catch (CodecConfigurationException e) { throw new CodecConfigurationException(String.format("Failed to encode '%s'. Encoding '%s' errored with: %s", morphiaCodec.getEntityModel().getName(), model.getMappedName(), e.getMessage()), e); } } } }
Example 2
Source File: GroupCodec.java From morphia with Apache License 2.0 | 6 votes |
@Override protected void encodeStage(final BsonWriter writer, final Group group, final EncoderContext encoderContext) { writer.writeStartDocument(); GroupId id = group.getId(); if (id != null) { writer.writeName("_id"); if(id.getDocument() != null) { id.getDocument().encode(getMapper(), writer, encoderContext); } else { id.getField().encode(getMapper(), writer, encoderContext); } } else { writer.writeNull("_id"); } Fields<Group> fields = group.getFields(); if(fields != null) { fields.encode(getMapper(), writer, encoderContext); } writer.writeEndDocument(); }
Example 3
Source File: MathExpression.java From morphia with Apache License 2.0 | 6 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName(getOperation()); if (operands.size() > 1) { writer.writeStartArray(); } for (final Expression operand : operands) { if (operand != null) { ExpressionCodec.writeUnnamedExpression(mapper, writer, operand, encoderContext); } else { writer.writeNull(); } } if (operands.size() > 1) { writer.writeEndArray(); } writer.writeEndDocument(); }
Example 4
Source File: EnumCodec.java From core-ng-project with Apache License 2.0 | 5 votes |
@Override public void encode(BsonWriter writer, T value, EncoderContext context) { if (value == null) { writer.writeNull(); } else { writer.writeString(encodingMappings.get(value)); } }
Example 5
Source File: LocaleCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final Locale value, final EncoderContext encoderContext) { if (value == null) { writer.writeNull(); } else { writer.writeString(value.toString()); } }
Example 6
Source File: CollectionCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final Collection<T> collection, final EncoderContext encoderContext) { writer.writeStartArray(); for (final T value : collection) { if (value == null) { writer.writeNull(); } else { codec.encode(writer, value, encoderContext); } } writer.writeEndArray(); }
Example 7
Source File: MorphiaMapPropertyCodecProvider.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final Map<K, V> map, final EncoderContext encoderContext) { writer.writeStartDocument(); for (final Entry<K, V> entry : map.entrySet()) { final K key = entry.getKey(); writer.writeName((String) Conversions.convert(key, String.class)); if (entry.getValue() == null) { writer.writeNull(); } else { codec.encode(writer, entry.getValue(), encoderContext); } } writer.writeEndDocument(); }
Example 8
Source File: Filter.java From morphia with Apache License 2.0 | 5 votes |
protected void writeNamedValue(final String name, final Object named, final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeName(name); if (named != null) { Codec codec = mapper.getCodecRegistry().get(named.getClass()); encoderContext.encodeWithChildContext(codec, writer, named); } else { writer.writeNull(); } }
Example 9
Source File: Filter.java From morphia with Apache License 2.0 | 5 votes |
protected void writeUnnamedValue(final Object value, final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { if (value != null) { Codec codec = mapper.getCodecRegistry().get(value.getClass()); encoderContext.encodeWithChildContext(codec, writer, value); } else { writer.writeNull(); } }
Example 10
Source File: ExpressionCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final T expression, final EncoderContext encoderContext) { if (expression != null) { expression.encode(mapper, writer, encoderContext); } else { writer.writeNull(); } }
Example 11
Source File: ValueExpression.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { if (getValue() != null) { Codec codec = mapper.getCodecRegistry().get(getValue().getClass()); encoderContext.encodeWithChildContext(codec, writer, getValue()); } else { writer.writeNull(); } }
Example 12
Source File: LocalDateTimeCodec.java From core-ng-project with Apache License 2.0 | 4 votes |
static void write(BsonWriter writer, LocalDateTime value) { if (value == null) writer.writeNull(); else writer.writeDateTime(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); }
Example 13
Source File: ZonedDateTimeCodec.java From core-ng-project with Apache License 2.0 | 4 votes |
static void write(BsonWriter writer, ZonedDateTime value) { if (value == null) writer.writeNull(); else writer.writeDateTime(value.toInstant().toEpochMilli()); }
Example 14
Source File: AbstractJsonCodec.java From vertx-mongo-client with Apache License 2.0 | 4 votes |
protected void writeNull(BsonWriter writer, String name, Object value, EncoderContext ctx) { writer.writeNull(); }