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

The following examples show how to use org.springframework.data.mongodb.core.convert.MongoCustomConversions. 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
Source Project: flow-platform-x   Source File: MongoConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();

    VariableMapConverter variableConverter = new VariableMapConverter(objectMapper);
    converters.add(variableConverter.getReader());
    converters.add(variableConverter.getWriter());

    EncryptConverter encryptConverter = new EncryptConverter(appProperties.getSecret());
    converters.add(encryptConverter.new SimpleKeyPairReader());
    converters.add(encryptConverter.new SimpleKeyPairWriter());
    converters.add(encryptConverter.new SimpleAuthPairReader());
    converters.add(encryptConverter.new SimpleAuthPairWriter());

    converters.add(new JobItem.ContextReader());
    return new MongoCustomConversions(converters);
}
 
Example 2
Source Project: flow-platform-x   Source File: MongoConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();

    VariableMapConverter variableConverter = new VariableMapConverter(objectMapper);
    converters.add(variableConverter.getReader());
    converters.add(variableConverter.getWriter());

    EncryptConverter encryptConverter = new EncryptConverter(appProperties.getSecret());
    converters.add(encryptConverter.new SimpleKeyPairReader());
    converters.add(encryptConverter.new SimpleKeyPairWriter());
    converters.add(encryptConverter.new SimpleAuthPairReader());
    converters.add(encryptConverter.new SimpleAuthPairWriter());
    converters.add(encryptConverter.new SimpleTokenReader());
    converters.add(encryptConverter.new SimpleTokenWriter());

    converters.add(new JobItem.ContextReader());
    return new MongoCustomConversions(converters);
}
 
Example 3
@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 4
@Bean
public MongoCustomConversions customConversions() {
	List<Converter<?,?>> converters = new ArrayList<>(2);
	converters.add(DBObjectToJsonNodeConverter.INSTANCE);
	converters.add(JsonNodeToDocumentConverter.INSTANCE);
	return new MongoCustomConversions(converters);
}
 
Example 5
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converterList = new ArrayList<>();
    converterList.add(DateToZonedDateTimeConverter.INSTANCE);
    converterList.add(ZonedDateTimeToDateConverter.INSTANCE);
    converterList.add(DurationToLongConverter.INSTANCE);
    return new MongoCustomConversions(converterList);
}
 
Example 6
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();
    converters.add(DateToZonedDateTimeConverter.INSTANCE);
    converters.add(ZonedDateTimeToDateConverter.INSTANCE);
    return new MongoCustomConversions(converters);
}
 
Example 7
Source Project: spring-fu   Source File: MongoReactiveDataInitializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	MongoReactiveDataAutoConfiguration configuration = new MongoReactiveDataAutoConfiguration();
	context.registerBean(MappingMongoConverter.class, () -> configuration.mappingMongoConverter(context.getBean(MongoMappingContext.class), context.getBean(MongoCustomConversions.class)));
	context.registerBean(SimpleReactiveMongoDatabaseFactory.class, () -> configuration.reactiveMongoDatabaseFactory(this.properties, context.getBean(MongoClient.class)));
	context.registerBean(ReactiveMongoTemplate.class, () -> configuration.reactiveMongoTemplate(context.getBean(ReactiveMongoDatabaseFactory.class), context.getBean(MongoConverter.class)));
}
 
Example 8
Source Project: spring-fu   Source File: MongoDataInitializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	MongoDataConfiguration dataConfiguration = new MongoDataConfiguration();
	context.registerBean(MongoCustomConversions.class, dataConfiguration::mongoCustomConversions);
	context.registerBean(MongoMappingContext.class, () -> {
		try {
			return dataConfiguration.mongoMappingContext(context, properties, context.getBean(MongoCustomConversions.class));
		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	});
	context.registerBean(MongoCustomConversions.class, dataConfiguration::mongoCustomConversions);
}
 
Example 9
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converterList = new ArrayList<>();
    converterList.add(DateToZonedDateTimeConverter.INSTANCE);
    converterList.add(ZonedDateTimeToDateConverter.INSTANCE);
    return new MongoCustomConversions(converterList);
}
 
Example 10
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();
    converters.add(DateToZonedDateTimeConverter.INSTANCE);
    converters.add(ZonedDateTimeToDateConverter.INSTANCE);
    return new MongoCustomConversions(converters);
}
 
Example 11
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converterList = new ArrayList<>();
    converterList.add(DateToZonedDateTimeConverter.INSTANCE);
    converterList.add(ZonedDateTimeToDateConverter.INSTANCE);
    return new MongoCustomConversions(converterList);
}
 
Example 12
@Bean
public MongoCustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();
    converters.add(DateToZonedDateTimeConverter.INSTANCE);
    converters.add(ZonedDateTimeToDateConverter.INSTANCE);
    return new MongoCustomConversions(converters);
}
 
Example 13
Source Project: jakduk-api   Source File: MongodbConfig.java    License: MIT License 5 votes vote down vote up
@Override
public CustomConversions customConversions() {
    List<Converter<?, ?>> converters = new ArrayList<>();
    converters.add(new DateToLocalDateTimeConverter());
    converters.add(new LocalDateTimeToDateConverter());
    return new MongoCustomConversions(converters);
}
 
Example 14
Source Project: tutorials   Source File: MongoConfig.java    License: MIT License 5 votes vote down vote up
@Override
public MongoCustomConversions customConversions() {
    converters.add(new UserWriterConverter());
    converters.add(new ZonedDateTimeReadConverter());
    converters.add(new ZonedDateTimeWriteConverter());
    return new MongoCustomConversions(converters);
}
 
Example 15
Source Project: entref-spring-boot   Source File: MongoConfig.java    License: MIT License 4 votes vote down vote up
@Override
public MongoCustomConversions customConversions() {
    return new MongoCustomConversions(converters);
}
 
Example 16
@Bean
public MongoCustomConversions customConversions() {
	return new MongoCustomConversions(Collections.singletonList(new MongoDbMessageBytesConverter()));
}
 
Example 17
@Setup
public void setUp() throws Exception {

	client = MongoClients.create();

	this.mappingContext = new MongoMappingContext();
	this.mappingContext.setInitialEntitySet(Collections.singleton(Customer.class));
	this.mappingContext.afterPropertiesSet();

	DbRefResolver dbRefResolver = new DefaultDbRefResolver(new SimpleMongoClientDatabaseFactory(client, DB_NAME));

	this.converter = new MappingMongoConverter(dbRefResolver, mappingContext);
	this.converter.setCustomConversions(new MongoCustomConversions(Collections.emptyList()));
	this.converter.afterPropertiesSet();

	// just a flat document
	this.documentWith2Properties = new Document("firstname", "Dave").append("lastname", "Matthews");

	// document with a nested one
	Document address = new Document("zipCode", "ABCDE").append("city", "Some Place");
	this.documentWith2PropertiesAnd1Nested = new Document("firstname", "Dave").//
			append("lastname", "Matthews").//
			append("address", address);

	// object equivalent of documentWith2PropertiesAnd1Nested
	this.objectWith2PropertiesAnd1Nested = new Customer("Dave", "Matthews", new Address("zipCode", "City"));

	// a bit more challenging object with list & map conversion.
	objectWithFlatAndComplexPropertiesPlusListAndMap = new SlightlyMoreComplexObject();
	objectWithFlatAndComplexPropertiesPlusListAndMap.id = UUID.randomUUID().toString();
	objectWithFlatAndComplexPropertiesPlusListAndMap.addressList = Arrays.asList(new Address("zip-1", "city-1"),
			new Address("zip-2", "city-2"));
	objectWithFlatAndComplexPropertiesPlusListAndMap.customer = objectWith2PropertiesAnd1Nested;
	objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap = new LinkedHashMap<>();
	objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("dave", objectWith2PropertiesAnd1Nested);
	objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("deborah",
			new Customer("Deborah Anne", "Dyer", new Address("?", "london")));
	objectWithFlatAndComplexPropertiesPlusListAndMap.customerMap.put("eddie",
			new Customer("Eddie", "Vedder", new Address("??", "Seattle")));
	objectWithFlatAndComplexPropertiesPlusListAndMap.intOne = Integer.MIN_VALUE;
	objectWithFlatAndComplexPropertiesPlusListAndMap.intTwo = Integer.MAX_VALUE;
	objectWithFlatAndComplexPropertiesPlusListAndMap.location = new Point(-33.865143, 151.209900);
	objectWithFlatAndComplexPropertiesPlusListAndMap.renamedField = "supercalifragilisticexpialidocious";
	objectWithFlatAndComplexPropertiesPlusListAndMap.stringOne = "¯\\_(ツ)_/¯";
	objectWithFlatAndComplexPropertiesPlusListAndMap.stringTwo = " (╯°□°)╯︵ ┻━┻";

	// JSON equivalent of objectWithFlatAndComplexPropertiesPlusListAndMap
	documentWithFlatAndComplexPropertiesPlusListAndMap = Document.parse(
			"{ \"_id\" : \"517f6aee-e9e0-44f0-88ed-f3694a019f27\", \"intOne\" : -2147483648, \"intTwo\" : 2147483647, \"stringOne\" : \"¯\\\\_(ツ)_/¯\", \"stringTwo\" : \" (╯°□°)╯︵ ┻━┻\", \"explicit-field-name\" : \"supercalifragilisticexpialidocious\", \"location\" : { \"x\" : -33.865143, \"y\" : 151.2099 }, \"objectWith2PropertiesAnd1Nested\" : { \"firstname\" : \"Dave\", \"lastname\" : \"Matthews\", \"address\" : { \"zipCode\" : \"zipCode\", \"city\" : \"City\" } }, \"addressList\" : [{ \"zipCode\" : \"zip-1\", \"city\" : \"city-1\" }, { \"zipCode\" : \"zip-2\", \"city\" : \"city-2\" }], \"customerMap\" : { \"dave\" : { \"firstname\" : \"Dave\", \"lastname\" : \"Matthews\", \"address\" : { \"zipCode\" : \"zipCode\", \"city\" : \"City\" } }, \"deborah\" : { \"firstname\" : \"Deborah Anne\", \"lastname\" : \"Dyer\", \"address\" : { \"zipCode\" : \"?\", \"city\" : \"london\" } }, \"eddie\" : { \"firstname\" : \"Eddie\", \"lastname\" : \"Vedder\", \"address\" : { \"zipCode\" : \"??\", \"city\" : \"Seattle\" } } }, \"_class\" : \"org.springframework.data.mongodb.core.convert.MappingMongoConverterBenchmark$SlightlyMoreComplexObject\" }");

}