Package org.bson.codecs.jsr310
Class LocalDateTimeCodec
- java.lang.Object
-
- org.bson.codecs.jsr310.LocalDateTimeCodec
-
- All Implemented Interfaces:
Codec<java.time.LocalDateTime>,Decoder<java.time.LocalDateTime>,Encoder<java.time.LocalDateTime>
public class LocalDateTimeCodec extends java.lang.ObjectLocalDateTime Codec.Encodes and decodes
LocalDateTimeobjects to and fromDateTime. Data is stored to millisecond accuracy.Converts the
LocalDateTimevalues to and fromZoneOffset.UTC.Note: Requires Java 8 or greater.
- Since:
- 3.7
- MongoDB documentation
- reference/bson-types
-
-
Constructor Summary
Constructors Constructor Description LocalDateTimeCodec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.LocalDateTimedecode(BsonReader reader, DecoderContext decoderContext)Decodes a BSON value from the given reader into an instance of the type parameterT.voidencode(BsonWriter writer, java.time.LocalDateTime value, EncoderContext encoderContext)Encode an instance of the type parameterTinto a BSON value.java.lang.Class<java.time.LocalDateTime>getEncoderClass()Returns the Class instance that this encodes.
-
-
-
Method Detail
-
decode
public java.time.LocalDateTime decode(BsonReader reader, DecoderContext decoderContext)
Description copied from interface:DecoderDecodes 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
public void encode(BsonWriter writer, java.time.LocalDateTime value, EncoderContext encoderContext)
Encode an instance of the type parameterTinto a BSON value.Converts the
LocalDateTimetoZoneOffset.UTCviaChronoLocalDateTime.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
public java.lang.Class<java.time.LocalDateTime> getEncoderClass()
Description copied from interface:EncoderReturns the Class instance that this encodes. This is necessary because Java does not reify generic types.- Returns:
- the Class instance that this encodes.
-
-