public class LocalDateCodec extends Object
Encodes and decodes LocalDate
objects to and from DateTime
.
Converts the LocalDate
values to and from ZoneOffset.UTC
.
Note: Requires Java 8 or greater.
Constructor | Description |
---|---|
LocalDateCodec() |
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 parameter
T . |
void |
encode(BsonWriter writer,
LocalDate value,
EncoderContext encoderContext) |
Encode an instance of the type parameter
T into a BSON value. |
Class<LocalDate> |
getEncoderClass() |
Returns the Class instance that this encodes.
|
public LocalDate decode(BsonReader reader, DecoderContext decoderContext)
Decoder
T
.reader
- the BSON readerdecoderContext
- the decoder contextT
.public void encode(BsonWriter writer, LocalDate value, EncoderContext encoderContext)
T
into a BSON value.
Converts the LocalDate
to ZoneOffset.UTC
via LocalDate.atStartOfDay(ZoneId)
.
writer
- the BSON writer to encode intovalue
- the value to encodeencoderContext
- the encoder contextCodecConfigurationException
- if the LocalDate cannot be converted to a valid Bson DateTime.