use of org.bson.codecs.pojo.entities.SimpleGenericsModel in project mongo-java-driver by mongodb.
the class ClassModelBuilderTest method testDefaults.
@Test
public void testDefaults() {
Class<SimpleGenericsModel> clazz = SimpleGenericsModel.class;
ClassModelBuilder<SimpleGenericsModel> builder = ClassModel.builder(clazz);
assertEquals(4, builder.getPropertyModelBuilders().size());
for (Field field : clazz.getDeclaredFields()) {
assertEquals(field.getName(), builder.getProperty(field.getName()).getWriteName());
}
Map<String, TypeParameterMap> fieldNameToTypeParameterMap = new HashMap<String, TypeParameterMap>();
fieldNameToTypeParameterMap.put("myIntegerField", TypeParameterMap.builder().build());
fieldNameToTypeParameterMap.put("myGenericField", TypeParameterMap.builder().addIndex(0).build());
fieldNameToTypeParameterMap.put("myListField", TypeParameterMap.builder().addIndex(0, 1).build());
fieldNameToTypeParameterMap.put("myMapField", TypeParameterMap.builder().addIndex(0, TypeParameterMap.builder().build()).addIndex(1, 2).build());
assertEquals(fieldNameToTypeParameterMap, builder.getPropertyNameToTypeParameterMap());
assertEquals(3, builder.getConventions().size());
assertTrue(builder.getAnnotations().isEmpty());
assertEquals(clazz, builder.getType());
assertNull(builder.getIdPropertyName());
assertFalse(builder.useDiscriminator());
assertNull(builder.getDiscriminator());
}
use of org.bson.codecs.pojo.entities.SimpleGenericsModel 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);
}
use of org.bson.codecs.pojo.entities.SimpleGenericsModel in project mongo-java-driver by mongodb.
the class PojoTestCase method getNestedGenericHolderSimpleGenericsModel.
static NestedGenericHolderSimpleGenericsModel getNestedGenericHolderSimpleGenericsModel() {
SimpleModel simpleModel = getSimpleModel();
Map<String, SimpleModel> map = new HashMap<String, SimpleModel>();
map.put("A", simpleModel);
Map<String, Map<String, SimpleModel>> mapB = new HashMap<String, Map<String, SimpleModel>>();
mapB.put("A", map);
SimpleGenericsModel<Integer, List<SimpleModel>, Map<String, SimpleModel>> simpleGenericsModel = new SimpleGenericsModel<Integer, List<SimpleModel>, Map<String, SimpleModel>>(42, 42, singletonList(singletonList(simpleModel)), mapB);
GenericHolderModel<SimpleGenericsModel<Integer, List<SimpleModel>, Map<String, SimpleModel>>> nested = new GenericHolderModel<SimpleGenericsModel<Integer, List<SimpleModel>, Map<String, SimpleModel>>>(simpleGenericsModel, 42L);
return new NestedGenericHolderSimpleGenericsModel(nested);
}
Aggregations