Search in sources :

Example 1 with PropertyWithMultipleTypeParamsModel

use of org.bson.codecs.pojo.entities.PropertyWithMultipleTypeParamsModel in project mongo-java-driver by mongodb.

the class PojoCustomTest method testMultiplePojoProviders.

@Test
public void testMultiplePojoProviders() {
    NestedGenericHolderFieldWithMultipleTypeParamsModel model = getNestedGenericHolderFieldWithMultipleTypeParamsModel();
    PojoCodecProvider provider1 = PojoCodecProvider.builder().register(NestedGenericHolderFieldWithMultipleTypeParamsModel.class).build();
    PojoCodecProvider provider2 = PojoCodecProvider.builder().register(PropertyWithMultipleTypeParamsModel.class).build();
    PojoCodecProvider provider3 = PojoCodecProvider.builder().register(SimpleGenericsModel.class).build();
    PojoCodecProvider provider4 = PojoCodecProvider.builder().register(GenericHolderModel.class).build();
    CodecRegistry registry = fromProviders(provider1, provider2, provider3, provider4);
    CodecRegistry actualRegistry = fromRegistries(fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider()), registry);
    String json = "{'nested': {'myGenericField': {_t: 'PropertyWithMultipleTypeParamsModel', " + "'simpleGenericsModel': {_t: 'org.bson.codecs.pojo.entities.SimpleGenericsModel', 'myIntegerField': 42, " + "'myGenericField': {'$numberLong': '101'}, 'myListField': ['B', 'C'], 'myMapField': {'D': 2, 'E': 3, 'F': 4 }}}," + "'myLongField': {'$numberLong': '42'}}}";
    roundTrip(actualRegistry, model, json);
}
Also used : BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider) ValueCodecProvider(org.bson.codecs.ValueCodecProvider) NestedGenericHolderFieldWithMultipleTypeParamsModel(org.bson.codecs.pojo.entities.NestedGenericHolderFieldWithMultipleTypeParamsModel) SimpleGenericsModel(org.bson.codecs.pojo.entities.SimpleGenericsModel) BsonRepresentationUnsupportedString(org.bson.codecs.pojo.entities.BsonRepresentationUnsupportedString) PropertyWithMultipleTypeParamsModel(org.bson.codecs.pojo.entities.PropertyWithMultipleTypeParamsModel) GenericHolderModel(org.bson.codecs.pojo.entities.GenericHolderModel) CodecRegistry(org.bson.codecs.configuration.CodecRegistry) BsonValueCodecProvider(org.bson.codecs.BsonValueCodecProvider) Test(org.junit.Test)

Aggregations

BsonValueCodecProvider (org.bson.codecs.BsonValueCodecProvider)1 ValueCodecProvider (org.bson.codecs.ValueCodecProvider)1 CodecRegistry (org.bson.codecs.configuration.CodecRegistry)1 BsonRepresentationUnsupportedString (org.bson.codecs.pojo.entities.BsonRepresentationUnsupportedString)1 GenericHolderModel (org.bson.codecs.pojo.entities.GenericHolderModel)1 NestedGenericHolderFieldWithMultipleTypeParamsModel (org.bson.codecs.pojo.entities.NestedGenericHolderFieldWithMultipleTypeParamsModel)1 PropertyWithMultipleTypeParamsModel (org.bson.codecs.pojo.entities.PropertyWithMultipleTypeParamsModel)1 SimpleGenericsModel (org.bson.codecs.pojo.entities.SimpleGenericsModel)1 Test (org.junit.Test)1