Package org.bson.codecs.jsr310
Class LocalDateCodec
- java.lang.Object
-
- org.bson.codecs.jsr310.LocalDateCodec
-
public class LocalDateCodec extends Object
LocalDate Codec.Encodes and decodes
LocalDate
objects to and fromDateTime
.Converts the
LocalDate
values to and fromZoneOffset.UTC
.Note: Requires Java 8 or greater.
- Since:
- 3.7
- MongoDB documentation
- reference/bson-types
-
-
Constructor Summary
Constructors Constructor Description LocalDateCodec()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalDate
decode(BsonReader reader, DecoderContext decoderContext)
Decodes a BSON value from the given reader into an instance of the type parameterT
.void
encode(BsonWriter writer, LocalDate value, EncoderContext encoderContext)
Encode an instance of the type parameterT
into a BSON value.Class<LocalDate>
getEncoderClass()
Returns the Class instance that this encodes.
-
-
-
Method Detail
-
decode
public LocalDate 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, LocalDate value, EncoderContext encoderContext)
Encode an instance of the type parameterT
into a BSON value.Converts the
LocalDate
toZoneOffset.UTC
viaLocalDate.atStartOfDay(ZoneId)
.- Parameters:
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder context- Throws:
CodecConfigurationException
- if the LocalDate cannot be converted to a valid Bson DateTime.
-
-