Java Code Examples for org.bson.BsonReader#readNull()
The following examples show how to use
org.bson.BsonReader#readNull() .
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: EnumCodec.java From core-ng-project with Apache License 2.0 | 6 votes |
public T read(BsonReader reader, String field) { BsonType currentType = reader.getCurrentBsonType(); if (currentType == BsonType.NULL) { reader.readNull(); return null; } else if (currentType == BsonType.STRING) { String enumValue = reader.readString(); T value = decodingMappings.get(enumValue); if (value == null) throw new Error(format("can not decode value to enum, enumClass={}, value={}", enumClass.getCanonicalName(), enumValue)); return value; } else { logger.warn("unexpected field type, field={}, type={}", field, currentType); reader.skipValue(); return null; } }
Example 2
Source File: MorphiaMapPropertyCodecProvider.java From morphia with Apache License 2.0 | 6 votes |
@Override public Map<K, V> decode(final BsonReader reader, final DecoderContext context) { reader.readStartDocument(); Map<K, V> map = getInstance(); while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { final K key = (K) Conversions.convert(reader.readName(), keyType); if (reader.getCurrentBsonType() == BsonType.NULL) { map.put(key, null); reader.readNull(); } else { map.put(key, codec.decode(reader, context)); } } reader.readEndDocument(); return map; }
Example 3
Source File: LocalDateTimeCodec.java From core-ng-project with Apache License 2.0 | 5 votes |
static LocalDateTime read(BsonReader reader, String field) { BsonType currentType = reader.getCurrentBsonType(); if (currentType == BsonType.NULL) { reader.readNull(); return null; } else if (currentType == BsonType.DATE_TIME) { return LocalDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneId.systemDefault()); } else { LOGGER.warn("unexpected field type, field={}, type={}", field, currentType); reader.skipValue(); return null; } }
Example 4
Source File: ZonedDateTimeCodec.java From core-ng-project with Apache License 2.0 | 5 votes |
static ZonedDateTime read(BsonReader reader, String field) { BsonType currentType = reader.getCurrentBsonType(); if (currentType == BsonType.NULL) { reader.readNull(); return null; } else if (currentType == BsonType.DATE_TIME) { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(reader.readDateTime()), ZoneId.systemDefault()); } else { LOGGER.warn("unexpected field type, field={}, type={}", field, currentType); reader.skipValue(); return null; } }
Example 5
Source File: OptionalProvider.java From immutables with Apache License 2.0 | 5 votes |
@Override public final O decode(BsonReader reader, DecoderContext decoderContext) { if (reader.getCurrentBsonType() == BsonType.NULL) { reader.readNull(); return empty(); } return nullable(delegate.decode(reader, decoderContext)); }
Example 6
Source File: ArrayCodec.java From morphia with Apache License 2.0 | 5 votes |
private Object readValue(final BsonReader reader, final DecoderContext decoderContext) { BsonType bsonType = reader.getCurrentBsonType(); if (bsonType == BsonType.NULL) { reader.readNull(); return null; } else if (bsonType == BsonType.BINARY && BsonBinarySubType.isUuid(reader.peekBinarySubType()) && reader.peekBinarySize() == 16) { return mapper.getCodecRegistry().get(UUID.class).decode(reader, decoderContext); } return mapper.getCodecRegistry().get(type.getComponentType()).decode(reader, decoderContext); }
Example 7
Source File: CollectionCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public Collection<T> decode(final BsonReader reader, final DecoderContext context) { Collection<T> collection = getInstance(); reader.readStartArray(); while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { if (reader.getCurrentBsonType() == BsonType.NULL) { collection.add(null); reader.readNull(); } else { collection.add(codec.decode(reader, context)); } } reader.readEndArray(); return collection; }
Example 8
Source File: AbstractJsonCodec.java From vertx-mongo-client with Apache License 2.0 | 4 votes |
protected Object readNull(BsonReader reader, DecoderContext ctx) { reader.readNull(); return null; }