本文整理汇总了Java中org.modelmapper.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于org.modelmapper包,在下文中一共展示了Converter类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ProductMapper
import org.modelmapper.Converter; //导入依赖的package包/类
public ProductMapper() {
// Converters for complex field conversions
// Converter<LocalDate, LocalDateTime> convertLocalDate2LocalDateTime = context -> context.getSource() == null ? null :
// context.getSource().atStartOfDay();
// Converter<LocalDateTime, LocalDate> convertLocalDateTime2LocalDate = context -> context.getSource() == null ? null :
// context.getSource().toLocalDate();
Converter<List<Category>, List<String>> convertCategory2Name = context -> context.getSource() == null ? null :
context.getSource().stream().map(Category::getName).collect(Collectors.toList());
Converter<List<String>, List<Category>> convertCategoryName2Category = context -> context.getSource() == null ? null :
context.getSource().stream().map((name) -> Category.builder().name(name).build()).collect(Collectors.toList());
// create PropertyMap<source,target> here and add to mapper
// map().set<Target>(source.get<Source>());
// map(source.get<Source>(), destination.get<Target>());
mapper.addMappings(new PropertyMap<Product, ProductDto>() {
@Override
protected void configure() {
using(convertCategory2Name).map(source.getCategories(), destination.getCategory());
}
});
mapper.addMappings(new PropertyMap<ProductDto, Product>() {
@Override
protected void configure() {
using(convertCategoryName2Category).map(source.getCategory(), destination.getCategories());
}
});
}
示例2: userMapping
import org.modelmapper.Converter; //导入依赖的package包/类
@Bean
public ConverterConfigurer<ProdType, ProdTypeDto> userMapping() {
return new ConverterConfigurer<ProdType, ProdTypeDto>() {
@Override
public Converter<ProdType, ProdTypeDto> converter() {
return new AbstractConverter<ProdType, ProdTypeDto>() {
@Override
protected ProdTypeDto convert(ProdType source) {
switch (source) {
case T1:
return ProdTypeDto.TYPE1;
case T2:
return ProdTypeDto.TYPE2;
}
return null;
}
};
}
};
}
示例3: bcryptConverter
import org.modelmapper.Converter; //导入依赖的package包/类
private Converter<String, String> bcryptConverter() {
return mappingContext -> encoder.encode(mappingContext.getSource());
}
示例4: modelMapper
import org.modelmapper.Converter; //导入依赖的package包/类
@Bean
public ModelMapper modelMapper(List<Converter> converters) {
ModelMapper mapper = new ModelMapper();
converters.stream().forEach(mapper::addConverter);
return mapper;
}
示例5: UserMapper
import org.modelmapper.Converter; //导入依赖的package包/类
public UserMapper() {
// Converters for complex field conversions
Converter<LocalDate, LocalDateTime> convertLocalDate2LocalDateTime = context -> context.getSource() == null ? null :
context.getSource().atStartOfDay();
Converter<LocalDateTime, LocalDate> convertLocalDateTime2LocalDate = context -> context.getSource() == null ? null :
context.getSource().toLocalDate();
// add PropertyMap<source,target> for unnatural field mappings
// map().set<Target>(source.get<Source>());
// map(source.get<Source>(), destination.get<Target>());
mapper.addMappings(new PropertyMap<User, UserDto>() {
@Override
protected void configure() {
map().setGivenName(source.getFirstname());
map().setFamilyName(source.getLastname());
using(convertLocalDate2LocalDateTime).map(source.getDob(), destination.getBday());
}
});
mapper.addMappings(new PropertyMap<UserDto, User>() {
@Override
protected void configure() {
map().setFirstname(source.getGivenName());
map().setLastname(source.getFamilyName());
using(convertLocalDateTime2LocalDate).map(source.getBday(), destination.getDob());
}
});
// add mapper.getTypeMap(<source>, <target>) pre/post conversion logic
}
示例6: ModelMapperAutoConfiguration
import org.modelmapper.Converter; //导入依赖的package包/类
public ModelMapperAutoConfiguration(ModelMapperProperties properties,
ObjectProvider<List<PropertyMap<?, ?>>> mappings,
ObjectProvider<List<Converter<?, ?>>> converters) {
this.properties = properties;
this.mappings = mappings.getIfAvailable();
this.converters = converters.getIfAvailable();
}
示例7: addConverters
import org.modelmapper.Converter; //导入依赖的package包/类
private void addConverters(ModelMapper modelMapper) {
if (this.properties.isAddConverters() && this.converters != null) {
for (Converter<?, ?> converter : this.converters) {
modelMapper.addConverter(converter);
}
}
}
示例8: converter
import org.modelmapper.Converter; //导入依赖的package包/类
public abstract Converter<S, D> converter();