本文整理了Java中org.modelmapper.ModelMapper
类的一些代码示例,展示了ModelMapper
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelMapper
类的具体详情如下:
包路径:org.modelmapper.ModelMapper
类名称:ModelMapper
[英]ModelMapper - Performs object mapping, maintains Configuration and stores TypeMap.
代码示例来源:origin: Raysmond/SpringBlog
public static <S, T> List<T> mapList(List<S> source, Class<T> targetClass) {
List<T> list = new ArrayList<>();
for (S s : source) {
list.add(getMapper().map(s, targetClass));
}
return list;
}
}
代码示例来源:origin: Vedenin/useful-java-links
public static void main(String[] args) {
// init mapper
PropertyMap<Source, Destination> orderMap = new PropertyMap<Source, Destination>() {
protected void configure() {
map().setText(source.getMessage());
}
};
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(orderMap);
// convert
Source source = new Source("Hello World!");
Destination destObject = modelMapper.map(source, Destination.class);
destObject.print(); // print Hello World!
}
}
代码示例来源:origin: Raysmond/SpringBlog
private static ModelMapper getMapper() {
if (MAPPER == null) {
MAPPER = new ModelMapper();
MAPPER.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
}
return MAPPER;
}
代码示例来源:origin: ldlqdsdcn/eidea4
/**
* 对象转换,把对象相同名字的属性复制给新对象
*
* @param obj 要转换的对象
* @param classOfT 转换后的类
* @return 转换后类的实例
*/
public static <T> T convertObject(Object obj, Class<T> classOfT) {
ModelMapper modelMapper = new ModelMapper();
return modelMapper.map(obj, classOfT);
}
代码示例来源:origin: getheimdall/heimdall
/**
* Converts a source to a type destination.
*
* @param source The source object
* @param typeDestination The type destination
* @return The object created
*/
public static <T, E> E mapper(T source, Class<E> typeDestination) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
return modelMapper.map(source, typeDestination);
}
代码示例来源:origin: getheimdall/heimdall
/**
* Converts a source to a type destination.
*
* @param source The souce object
* @param typeDestination The type destination
* @param mapping The properties for the mapping process
* @return The object created
*/
public static <T, E> E mapperWithMapping(T source, Class<E> typeDestination, PropertyMap<T, E> mapping) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
modelMapper.addMappings(mapping);
return modelMapper.map(source, typeDestination);
}
代码示例来源:origin: stackoverflow.com
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
protected void configure() {
map().setBillingStreet(source.getBillingStreetAddress());
skip().setBillingCity(null);
}
});
代码示例来源:origin: stackoverflow.com
public void TestThis(){
final ModelMapper mapper = new ModelMapper();
mapper.addMappings(new PropertyMap<SrcClass, DestClass>() {
@Override
protected void configure() {
this.map().setId(this.source.getId());
this.map().setName(this.source.getName());
mapper.createTypeMap(TypeEnum.class, TypeClass.class).setConverter(
new Converter<TypeEnum, TypeClass>() {
@Override
srcObj.setTypes(new HashSet<>(Arrays.asList(TypeEnum.TYPE1, TypeEnum.TYPE2)));
DestClass dstObj = mapper.map(srcObj, DestClass.class);
代码示例来源:origin: stackoverflow.com
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().setProvider(providerVo);
mapper.addConverter(converterDtoToVo);
代码示例来源:origin: ConsenSys/eventeum
public Web3jTransactionReceipt(
org.web3j.protocol.core.methods.response.TransactionReceipt web3TransactionReceipt) {
logs = convertLogs(web3TransactionReceipt.getLogs());
try {
final ModelMapper modelMapper = ModelMapperFactory.getInstance().createModelMapper();
//Skip logs
modelMapper.getConfiguration().setPropertyCondition(ctx ->
!ctx.getMapping().getLastDestinationProperty().getName().equals("logs"));
modelMapper.map(web3TransactionReceipt, this);
} catch (RuntimeException re) {
re.printStackTrace();
throw re;
}
}
代码示例来源:origin: stackoverflow.com
ModelMapper modelMapper = new ModelMapper();
List<Mapping> mappings = modelMapper.createTypeMap(Source.class, Dest.class).getMappings();
代码示例来源:origin: arey/java-object-mapper-benchmark
public ModelMapper() {
modelMapper = new org.modelmapper.ModelMapper();
modelMapper.addMappings(new PropertyMap<Order, OrderDTO>() {
@Override
protected void configure() {
map().setBillingStreetAddress(source.getCustomer().getBillingAddress().getStreet());
map().setBillingCity(source.getCustomer().getBillingAddress().getCity());
map().setShippingStreetAddress(source.getCustomer().getShippingAddress().getStreet());
map().setShippingCity(source.getCustomer().getShippingAddress().getCity());
}
});
}
代码示例来源:origin: stackoverflow.com
ModelMapper mapper = new ModelMapper();
mapper.addConverter(converter);
代码示例来源:origin: ldlqdsdcn/eidea4
public SearchServiceImpl()
{
modelMapper.addMappings(new PropertyMap<SearchColumnPo, SearchColumnBo>() {
@Override
protected void configure() {
map().setLabelKey(source.getCoreLabel().getKey());
}
});
}
@Override
代码示例来源:origin: Caratacus/Crown
@Override
public void setupModule(ModelMapper modelMapper) {
modelMapper.getConfiguration().getConverters().add(0, new FromTemporalConverter(config));
modelMapper.getConfiguration().getConverters().add(0, new ToTemporalConverter(config));
modelMapper.getConfiguration().getConverters().add(0, new TemporalToTemporalConverter());
}
}
代码示例来源:origin: bramp/ffmpeg-cli-wrapper
private static <S, D> TypeMap<S, D> createTypeMap(
ModelMapper mapper, Class<S> sourceType, Class<D> destinationType, Configuration config) {
return mapper
.createTypeMap(sourceType, destinationType, config)
// We setPropertyCondition because ModelMapper seems to ignore this in
// the config
.setPropertyCondition(config.getPropertyCondition());
}
代码示例来源:origin: stackoverflow.com
ModelMapper modelMapper = new ModelMapper();
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);
代码示例来源:origin: getheimdall/heimdall
/**
* Converts a source to a type destination.
*
* @param source The source object
* @param destination The destination object
* @return The object created
*/
public static <T, E> E mapper(T source, E destination) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
modelMapper.map(source, destination);
return destination;
}
代码示例来源:origin: getheimdall/heimdall
/**
* Converts a source to a type destination.
*
* @param source The souce object
* @param destination The destination object
* @param mapping The properties for the mapping process
* @return The object created
*/
public static <T, E> E mapperWithMapping(T source, E destination, PropertyMap<T, E> mapping) {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
modelMapper.addMappings(mapping);
modelMapper.map(source, destination);
return destination;
}
代码示例来源:origin: stackoverflow.com
ModelMapper modelMapper = new ModelMapper();
modelMapper.addMappings(new PropertyMap<SourceClass, DestClass>() {
protected void configure() {
map().setSomeProperty(someConstant);
}
});
内容来源于网络,如有侵权,请联系作者删除!