All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mongovalues.JsInstantCodec Maven / Gradle / Ivy

Go to download

Set of codecs to add support for json-values in the Java MongoDB driver, abstracting the process of decoding a BSON into a JsObj and encoding a JsObj into a BSON.

There is a newer version: 2.0.0
Show newest version
package mongovalues;

import jsonvalues.JsInstant;
import org.bson.BsonReader;
import org.bson.BsonWriter;
import org.bson.codecs.Codec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;
import org.bson.codecs.jsr310.InstantCodec;

class JsInstantCodec implements Codec {

    private static final InstantCodec instantCodec = new InstantCodec();

    @Override
    public void encode(final BsonWriter writer, final JsInstant jsInstant, final EncoderContext encoderContext) {

        instantCodec.encode(writer, jsInstant.value, encoderContext);

    }

    @Override
    public JsInstant decode(final BsonReader reader, final DecoderContext decoderContext) {

        return JsInstant.of(instantCodec.decode(reader,
                decoderContext)
        );

    }

    @Override
    public Class getEncoderClass() {
        return JsInstant.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy