Search in sources :

Example 1 with SimpleNestedPojoModel

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

the class PojoCustomTest method testCanHandleNullValuesForNestedModels.

@Test
@SuppressWarnings("unchecked")
public void testCanHandleNullValuesForNestedModels() {
    SimpleNestedPojoModel model = getSimpleNestedPojoModel();
    model.setSimple(null);
    ClassModelBuilder<SimpleNestedPojoModel> classModel = ClassModel.builder(SimpleNestedPojoModel.class);
    ((PropertyModelBuilder<SimpleModel>) classModel.getProperty("simple")).propertySerialization(new PropertySerialization<SimpleModel>() {

        @Override
        public boolean shouldSerialize(final SimpleModel value) {
            return true;
        }
    });
    ClassModelBuilder<SimpleModel> classModelSimple = ClassModel.builder(SimpleModel.class);
    roundTrip(getPojoCodecProviderBuilder(classModel, classModelSimple), model, "{'simple': null}");
}
Also used : SimpleModel(org.bson.codecs.pojo.entities.SimpleModel) SimpleNestedPojoModel(org.bson.codecs.pojo.entities.SimpleNestedPojoModel) Test(org.junit.Test)

Aggregations

SimpleModel (org.bson.codecs.pojo.entities.SimpleModel)1 SimpleNestedPojoModel (org.bson.codecs.pojo.entities.SimpleNestedPojoModel)1 Test (org.junit.Test)1