public class LocalDateTimeCodec
extends java.lang.Object
Encodes and decodes LocalDateTime
objects to and from DateTime
. Data is stored to millisecond accuracy.
Converts the LocalDateTime
values to and from ZoneOffset.UTC
.
Note: Requires Java 8 or greater.
Constructor and Description |
---|
LocalDateTimeCodec() |
Modifier and Type | Method and Description |
---|---|
java.time.LocalDateTime |
decode(BsonReader reader,
DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameter
T . |
void |
encode(BsonWriter writer,
java.time.LocalDateTime value,
EncoderContext encoderContext)
Encode an instance of the type parameter
T into a BSON value. |
java.lang.Class<java.time.LocalDateTime> |
getEncoderClass()
Returns the Class instance that this encodes.
|
public java.time.LocalDateTime decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.reader
- the BSON readerdecoderContext
- the decoder contextT
.public void encode(BsonWriter writer, java.time.LocalDateTime value, EncoderContext encoderContext)
T
into a BSON value.
Converts the LocalDateTime
to ZoneOffset.UTC
via ChronoLocalDateTime.toInstant(ZoneOffset)
.
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder contextCodecConfigurationException
- if the LocalDateTime cannot be converted to a valid Bson DateTime.public java.lang.Class<java.time.LocalDateTime> getEncoderClass()
Encoder