Package org.bson.codecs.jsr310
Class LocalDateTimeCodec
java.lang.Object
org.bson.codecs.jsr310.LocalDateTimeCodec
- All Implemented Interfaces:
Codec<LocalDateTime>
,Decoder<LocalDateTime>
,Encoder<LocalDateTime>
LocalDateTime Codec.
Encodes and decodes LocalDateTime
objects to and from DateTime
. Data is stored to millisecond accuracy.
Converts the LocalDateTime
values to and from ZoneOffset.UTC
.
- Since:
- 3.7
- MongoDB documentation
- reference/bson-types
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondecode
(BsonReader reader, DecoderContext decoderContext) Decodes a BSON value from the given reader into an instance of the type parameterT
.void
encode
(BsonWriter writer, LocalDateTime value, EncoderContext encoderContext) Encode an instance of the type parameterT
into a BSON value.Returns the Class instance that this encodes.
-
Constructor Details
-
LocalDateTimeCodec
public LocalDateTimeCodec()
-
-
Method Details
-
decode
Description copied from interface:Decoder
Decodes a BSON value from the given reader into an instance of the type parameterT
.- Parameters:
reader
- the BSON readerdecoderContext
- the decoder context- Returns:
- an instance of the type parameter
T
.
-
encode
Encode an instance of the type parameterT
into a BSON value.Converts the
LocalDateTime
toZoneOffset.UTC
viaChronoLocalDateTime.toInstant(ZoneOffset)
.- Parameters:
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder context- Throws:
CodecConfigurationException
- if the LocalDateTime cannot be converted to a valid Bson DateTime.
-
getEncoderClass
Description copied from interface:Encoder
Returns the Class instance that this encodes. This is necessary because Java does not reify generic types.- Returns:
- the Class instance that this encodes.
-