Java Code Examples for org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper

The following examples show how to use org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
public MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory, SequenceOption sequenceOption) {
	DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);

	MongoCustomConversions conversions = new MongoCustomConversions(resolverConverter());
	MongoMappingContext mappingContext = new BHBMongoMappingContext();
	mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
	mappingContext.afterPropertiesSet();
	MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
	// _class 剔除
	converter.setTypeMapper(new DefaultMongoTypeMapper(null));
	converter.setCustomConversions(conversions);
	converter.afterPropertiesSet();

	// 需要自增时
	// MongoTemplate template=new DTXDMongoTemplate(mongoDbFactory,converter,
	// sequenceOption);
	MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
	return template;
}
 
Example 2
Source Project: Lottor   Source File: TxManagerConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
@Override
public MappingMongoConverter mappingMongoConverter() throws Exception {
    MappingMongoConverter mmc = super.mappingMongoConverter();
    mmc.setTypeMapper(new DefaultMongoTypeMapper(null));
    return mmc;
}
 
Example 3
Source Project: canal-mongo   Source File: MultipleMongoConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Primary
@Bean(name = "naiveMongoTemplate")
public MongoTemplate naiveMongoTemplate() throws Exception {
    MappingMongoConverter converter =
            new MappingMongoConverter(new DefaultDbRefResolver(naiveFactory()), new MongoMappingContext());
    converter.setTypeMapper(new DefaultMongoTypeMapper(null));
    return new MongoTemplate(naiveFactory(), converter);
}
 
Example 4
Source Project: canal-mongo   Source File: MultipleMongoConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@Qualifier("completeMongoTemplate")
public MongoTemplate completeMongoTemplate() throws Exception {
    MappingMongoConverter converter =
            new MappingMongoConverter(new DefaultDbRefResolver(completeFactory()), new MongoMappingContext());
    converter.setTypeMapper(new DefaultMongoTypeMapper(null));
    return new MongoTemplate(completeFactory(), converter);
}
 
Example 5
Source Project: ClusterDeviceControlPlatform   Source File: KyMongoConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@Override
public MappingMongoConverter mappingMongoConverter() throws Exception {
    MappingMongoConverter mmc = super.mappingMongoConverter();
    //remove _class
    mmc.setTypeMapper(new DefaultMongoTypeMapper(null));
    return mmc;
}
 
Example 6
Source Project: ClusterDeviceControlPlatform   Source File: KyMongoConfig.java    License: MIT License 5 votes vote down vote up
@Override
public MappingMongoConverter mappingMongoConverter() throws Exception {
    MappingMongoConverter mmc = super.mappingMongoConverter();
    //remove _class
    mmc.setTypeMapper(new DefaultMongoTypeMapper(null));
    return mmc;
}
 
Example 7
@Bean(name = "mongoTemplate")
public MongoTemplate createMongoTemplate() throws UnknownHostException {
    MongoClient mongoClient = new MongoClient(host, port);
    //TODO Configure additional MongoDB mongoClient settings if needed
    MongoDbFactory factory = new SimpleMongoDbFactory(mongoClient, database, new UserCredentials(username, password));
    MappingMongoConverter converter = new MappingMongoConverter(new DefaultDbRefResolver(factory), new MongoMappingContext());
    converter.setTypeMapper(new DefaultMongoTypeMapper(null));

    return new MongoTemplate(factory, converter);
}
 
Example 8
@Override
public MappingMongoConverter getObject() throws Exception {
	MongoTypeMapper typeMapper = new DefaultMongoTypeMapper(null);
	converter.setTypeMapper(typeMapper);
	return converter;
}