use of org.bson.codecs.pojo.entities.SimpleModel in project mongo-java-driver by mongodb.
the class PojoCodecProviderTest method testClassNotFound.
@Test
public void testClassNotFound() {
PojoCodecProvider provider = PojoCodecProvider.builder().build();
CodecRegistry registry = fromProviders(provider, new ValueCodecProvider());
Codec<SimpleModel> codec = provider.get(SimpleModel.class, registry);
assertNull(codec);
}
use of org.bson.codecs.pojo.entities.SimpleModel in project mongo-java-driver by mongodb.
the class PojoCodecCyclicalLookupTest method testSimpleModel.
@Test
void testSimpleModel() {
SimpleModel model = getSimpleModel();
LookupCountingCodecRegistry registry = createRegistry(SimpleModel.class);
roundTrip(registry, model, SIMPLE_MODEL_JSON);
// Looked up in encodesTo & decodesTo
assertEquals(2, registry.counters.get(SimpleModel.class).get());
// Lookup on encode then cached (PropertyCodecRegistry)
assertEquals(1, registry.counters.get(String.class).get());
// Lookup on encode then cached (PropertyCodecRegistry)
assertEquals(1, registry.counters.get(Integer.class).get());
}
use of org.bson.codecs.pojo.entities.SimpleModel in project mongo-java-driver by mongodb.
the class PojoCodecProviderTest method testAutomatic.
@Test
public void testAutomatic() {
PojoCodecProvider provider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry registry = fromProviders(provider, new ValueCodecProvider());
Codec<SimpleModel> codec = provider.get(SimpleModel.class, registry);
assertNotNull(codec);
}
use of org.bson.codecs.pojo.entities.SimpleModel 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}");
}
use of org.bson.codecs.pojo.entities.SimpleModel in project mongo-java-driver by mongodb.
the class PojoCustomTest method testCustomPropertySerializer.
@Test
@SuppressWarnings("unchecked")
public void testCustomPropertySerializer() {
SimpleModel model = getSimpleModel();
model.setIntegerField(null);
ClassModelBuilder<SimpleModel> classModel = ClassModel.builder(SimpleModel.class);
((PropertyModelBuilder<Integer>) classModel.getProperty("integerField")).propertySerialization(new PropertySerialization<Integer>() {
@Override
public boolean shouldSerialize(final Integer value) {
return true;
}
});
roundTrip(getPojoCodecProviderBuilder(classModel), model, "{'integerField': null, 'stringField': 'myString'}");
}
Aggregations