Codec<LocalDateTime>
, Decoder<LocalDateTime>
, Encoder<LocalDateTime>
public class LocalDateTimeCodec extends 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 | Description |
---|---|
LocalDateTimeCodec() |
Modifier and Type | Method | Description |
---|---|---|
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,
LocalDateTime value,
EncoderContext encoderContext) |
Encode an instance of the type parameter
T into a BSON value. |
Class<LocalDateTime> |
getEncoderClass() |
Returns the Class instance that this encodes.
|
public LocalDateTime decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.reader
- the BSON readerdecoderContext
- the decoder contextT
.public void encode(BsonWriter writer, 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 Class<LocalDateTime> getEncoderClass()
Encoder