Search in sources :

Example 1 with Jsr310CodecProvider

use of org.bson.codecs.jsr310.Jsr310CodecProvider in project immutables by immutables.

the class BsonModule method defaultRegistry.

private static CodecRegistry defaultRegistry() {
    CodecRegistry standard = CodecRegistries.fromProviders(new BsonValueCodecProvider(), new Jsr310CodecProvider());
    // avoid codecs for String / Long / Boolean etc. They're already handled by jackson
    // choose the ones which need to be natively serialized in non-JSON format (BSON)
    CodecRegistry others = CodecRegistries.fromCodecs(new ObjectIdCodec(), new DateCodec(), new UuidCodec(UuidRepresentation.JAVA_LEGACY), new Decimal128Codec(), new PatternCodec(), new BigDecimalCodec(), new ByteArrayCodec());
    return CodecRegistries.fromRegistries(standard, others);
}
Also used : ByteArrayCodec(org.bson.codecs.ByteArrayCodec) UuidCodec(org.bson.codecs.UuidCodec) Jsr310CodecProvider(org.bson.codecs.jsr310.Jsr310CodecProvider) ObjectIdCodec(org.bson.codecs.ObjectIdCodec) DateCodec(org.bson.codecs.DateCodec) Decimal128Codec(org.bson.codecs.Decimal128Codec) BigDecimalCodec(org.bson.codecs.BigDecimalCodec) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) PatternCodec(org.bson.codecs.PatternCodec) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider)

Example 2 with Jsr310CodecProvider

use of org.bson.codecs.jsr310.Jsr310CodecProvider in project immutables by immutables.

the class JavaTimeTest method setUp.

@Before
public void setUp() {
    CodecRegistry registry = CodecRegistries.fromProviders(new Jsr310CodecProvider());
    TypeAdapterFactory factory = GsonCodecs.delegatingTypeAdapterFactory(registry);
    TypeAdapter<Date> dateTypeAdapter = GsonCodecs.typeAdapterFromCodec(new DateCodec());
    gson = new GsonBuilder().registerTypeAdapter(Date.class, dateTypeAdapter).registerTypeAdapterFactory(factory).create();
}
Also used : TypeAdapterFactory(com.google.gson.TypeAdapterFactory) GsonBuilder(com.google.gson.GsonBuilder) Jsr310CodecProvider(org.bson.codecs.jsr310.Jsr310CodecProvider) DateCodec(org.bson.codecs.DateCodec) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) Date(java.util.Date) LocalDate(java.time.LocalDate) Before(org.junit.Before)

Aggregations

DateCodec (org.bson.codecs.DateCodec)2 CodecRegistry (org.bson.codecs.configuration.CodecRegistry)2 Jsr310CodecProvider (org.bson.codecs.jsr310.Jsr310CodecProvider)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeAdapterFactory (com.google.gson.TypeAdapterFactory)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 BigDecimalCodec (org.bson.codecs.BigDecimalCodec)1 BsonValueCodecProvider (org.bson.codecs.BsonValueCodecProvider)1 ByteArrayCodec (org.bson.codecs.ByteArrayCodec)1 Decimal128Codec (org.bson.codecs.Decimal128Codec)1 ObjectIdCodec (org.bson.codecs.ObjectIdCodec)1 PatternCodec (org.bson.codecs.PatternCodec)1 UuidCodec (org.bson.codecs.UuidCodec)1 Before (org.junit.Before)1