Search in sources :

Example 1 with NestedGenericHolderFieldWithMultipleTypeParamsModel

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

the class PojoCodecCyclicalLookupTest method testNestedGenericHolderFieldWithMultipleTypeParamsModel.

@Test
void testNestedGenericHolderFieldWithMultipleTypeParamsModel() {
    NestedGenericHolderFieldWithMultipleTypeParamsModel model = getNestedGenericHolderFieldWithMultipleTypeParamsModel();
    LookupCountingCodecRegistry registry = createRegistry(NestedGenericHolderFieldWithMultipleTypeParamsModel.class, PropertyWithMultipleTypeParamsModel.class, SimpleGenericsModel.class, GenericHolderModel.class);
    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(registry, model, json);
    assertEquals(2, registry.counters.get(NestedGenericHolderFieldWithMultipleTypeParamsModel.class).get());
    assertEquals(1, registry.counters.get(PropertyWithMultipleTypeParamsModel.class).get());
    assertEquals(1, registry.counters.get(SimpleGenericsModel.class).get());
    assertEquals(1, registry.counters.get(GenericHolderModel.class).get());
    assertEquals(1, registry.counters.get(Long.class).get());
    assertEquals(1, registry.counters.get(String.class).get());
    assertEquals(1, registry.counters.get(Integer.class).get());
}
Also used : NestedGenericHolderFieldWithMultipleTypeParamsModel(org.bson.codecs.pojo.entities.NestedGenericHolderFieldWithMultipleTypeParamsModel) Test(org.junit.jupiter.api.Test)

Example 2 with NestedGenericHolderFieldWithMultipleTypeParamsModel

use of org.bson.codecs.pojo.entities.NestedGenericHolderFieldWithMultipleTypeParamsModel 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

NestedGenericHolderFieldWithMultipleTypeParamsModel (org.bson.codecs.pojo.entities.NestedGenericHolderFieldWithMultipleTypeParamsModel)2 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 PropertyWithMultipleTypeParamsModel (org.bson.codecs.pojo.entities.PropertyWithMultipleTypeParamsModel)1 SimpleGenericsModel (org.bson.codecs.pojo.entities.SimpleGenericsModel)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1