Class InstantCodec

java.lang.Object
org.bson.codecs.jsr310.InstantCodec
All Implemented Interfaces:
Codec<Instant>, Decoder<Instant>, Encoder<Instant>

public class InstantCodec extends Object
Instant Codec.

Encodes and decodes Instant objects to and from DateTime. Data is extracted via Instant.toEpochMilli() and stored to millisecond accuracy.

Since:
3.7
MongoDB documentation
reference/bson-types
  • Constructor Details

    • InstantCodec

      public InstantCodec()
  • Method Details

    • decode

      public Instant decode(BsonReader reader, DecoderContext decoderContext)
      Description copied from interface: Decoder
      Decodes a BSON value from the given reader into an instance of the type parameter T.
      Parameters:
      reader - the BSON reader
      decoderContext - the decoder context
      Returns:
      an instance of the type parameter T.
    • encode

      public void encode(BsonWriter writer, Instant value, EncoderContext encoderContext)
      Encode an instance of the type parameter T into a BSON value.
      Parameters:
      writer - the BSON writer to encode into
      value - the value to encode
      encoderContext - the encoder context
      Throws:
      CodecConfigurationException - if the Instant cannot be converted to a valid Bson DateTime.
    • getEncoderClass

      public Class<Instant> 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.