Package org.bson.codecs.jsr310
Class LocalTimeCodec
- java.lang.Object
-
- org.bson.codecs.jsr310.LocalTimeCodec
-
- All Implemented Interfaces:
Codec<java.time.LocalTime>
,Decoder<java.time.LocalTime>
,Encoder<java.time.LocalTime>
public class LocalTimeCodec extends java.lang.Object
LocalTime Codec.Encodes and decodes
LocalTime
objects to and fromDateTime
. Data is stored to millisecond accuracy.Converts the
LocalTime
values to and from EpochDay atZoneOffset.UTC
.Note: Requires Java 8 or greater.
- Since:
- 3.7
- MongoDB documentation
- reference/bson-types
-
-
Constructor Summary
Constructors Constructor Description LocalTimeCodec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.LocalTime
decode(BsonReader reader, DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameterT
.void
encode(BsonWriter writer, java.time.LocalTime value, EncoderContext encoderContext)
Encode an instance of the type parameterT
into a BSON value.java.lang.Class<java.time.LocalTime>
getEncoderClass()
Returns the Class instance that this encodes.
-
-
-
Method Detail
-
decode
public java.time.LocalTime decode(BsonReader reader, DecoderContext decoderContext)
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
public void encode(BsonWriter writer, java.time.LocalTime value, EncoderContext encoderContext)
Encode an instance of the type parameterT
into a BSON value.Converts the
LocalTime
toZoneOffset.UTC
at EpochDay viaLocalTime.atDate(LocalDate)
andChronoLocalDateTime.toInstant(ZoneOffset)
.- Parameters:
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder context
-
getEncoderClass
public java.lang.Class<java.time.LocalTime> 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.
-
-