use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.
the class AbstractReactiveMongoConfiguration method mappingMongoConverter.
/**
* Creates a {@link MappingMongoConverter} using the configured {@link #reactiveMongoDbFactory()} and
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
*
* @see #customConversions()
* @see #mongoMappingContext()
* @see #reactiveMongoDbFactory()
* @return never {@literal null}.
* @throws Exception
*/
@Bean
public MappingMongoConverter mappingMongoConverter() throws Exception {
MappingMongoConverter converter = new MappingMongoConverter(ReactiveMongoTemplate.NO_OP_REF_RESOLVER, mongoMappingContext());
converter.setCustomConversions(customConversions());
return converter;
}
use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.
the class SpelExpressionTransformerIntegrationTests method shouldThrowExceptionIfNestedPropertyCannotBeFound.
// DATAMONGO-774
@Test
public void shouldThrowExceptionIfNestedPropertyCannotBeFound() {
exception.expect(MappingException.class);
exception.expectMessage("value2");
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class, new MongoMappingContext(), new QueryMapper(converter));
assertThat(transformer.transform("item.value2", ctxt, new Object[0]).toString(), is("$item.value2"));
}
use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.
the class SpelExpressionTransformerIntegrationTests method shouldConvertCompoundExpressionToPropertyPath.
// DATAMONGO-774
@Test
public void shouldConvertCompoundExpressionToPropertyPath() {
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
TypeBasedAggregationOperationContext ctxt = new TypeBasedAggregationOperationContext(Data.class, new MongoMappingContext(), new QueryMapper(converter));
assertThat(transformer.transform("item.primitiveIntValue", ctxt, new Object[0]).toString(), is("$item.primitiveIntValue"));
}
use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.
the class StringBasedMongoQueryUnitTests method setUp.
@Before
public void setUp() {
this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
doReturn(findOperation).when(operations).query(any());
}
use of org.springframework.data.mongodb.core.convert.MappingMongoConverter in project spring-data-mongodb by spring-projects.
the class SpringDataMongodbSerializerUnitTests method takesCustomConversionForEnumsIntoAccount.
// DATAMONGO-1485
@Test
public void takesCustomConversionForEnumsIntoAccount() {
MongoMappingContext context = new MongoMappingContext();
MappingMongoConverter converter = new MappingMongoConverter(dbFactory, context);
converter.setCustomConversions(new MongoCustomConversions(Collections.singletonList(new SexTypeWriteConverter())));
converter.afterPropertiesSet();
this.converter = converter;
this.serializer = new SpringDataMongodbSerializer(this.converter);
Object mappedPredicate = this.serializer.handle(QPerson.person.sex.eq(Sex.FEMALE));
assertThat(mappedPredicate, is(instanceOf(DBObject.class)));
assertThat(((DBObject) mappedPredicate).get("sex"), is((Object) "f"));
}
Aggregations