org.modelmapper.PropertyMap Java Examples
The following examples show how to use
org.modelmapper.PropertyMap.
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 File: ApplicationsService.java From realworld-serverless-application with Apache License 2.0 | 6 votes |
private static ModelMapper configureModelMapper() { ModelMapper modelMapper = new ModelMapper(); PropertyMap<ApplicationRecord, Application> applicationMap = new PropertyMap<ApplicationRecord, Application>() { protected void configure() { map(source.getCreatedAt()).setCreationTime(null); } }; PropertyMap<ApplicationRecord, ApplicationSummary> applicationSummaryMap = new PropertyMap<ApplicationRecord, ApplicationSummary>() { protected void configure() { map(source.getCreatedAt()).setCreationTime(null); } }; modelMapper.addMappings(applicationMap); modelMapper.addMappings(applicationSummaryMap); return modelMapper; }
Example #2
Source File: ModelMappingConfig.java From production-ready-microservices-starter with MIT License | 6 votes |
private void addMappingSiteCreateUpdateRequestToSite(ModelMapper mapper) { PropertyMap propertyMap = new PropertyMap<SiteCreateUpdateRequest, Site>() { @Override protected void configure() { skip(destination.getId()); skip(destination.getCreatedBy()); skip(destination.getUpdatedBy()); skip(destination.getCreatedAt()); skip(destination.getUpdatedAt()); skip(destination.getOrg()); skip(destination.getTenant()); } }; mapper.createTypeMap(SiteCreateUpdateRequest.class, Site.class).addMappings(propertyMap); mapper.validate(); }
Example #3
Source File: AccessTokenService.java From heimdall with Apache License 2.0 | 6 votes |
/** * Updates a {@link AccessToken} by its ID. * * @param id The ID of the {@link AccessToken} to be updated * @param accessTokenPersist {@link AccessTokenPersist} The request for {@link AccessToken} * @return The {@link AccessToken} updated */ @Transactional public AccessToken update(Long id, AccessTokenPersist accessTokenPersist) { AccessToken accessToken = accessTokenRepository.findOne(id); HeimdallException.checkThrow(accessToken == null, GLOBAL_RESOURCE_NOT_FOUND); App appRecover = appRespository.findOne(accessTokenPersist.getApp().getId()); HeimdallException.checkThrow(appRecover == null, APP_NOT_EXIST); HeimdallException.checkThrow(!verifyIfPlansContainsInApp(appRecover, accessTokenPersist.getPlans()), SOME_PLAN_NOT_PRESENT_IN_APP); PropertyMap<AccessTokenPersist, AccessToken> propertyMap = new PropertyMap<AccessTokenPersist, AccessToken>() { @Override protected void configure() { skip(destination.getCode()); } }; GenericConverter.convertWithMapping(accessTokenPersist, accessToken, propertyMap); accessToken = accessTokenRepository.save(accessToken); amqpCacheService.dispatchClean(); return accessToken; }
Example #4
Source File: ProductMapper.java From research-graphql with MIT License | 6 votes |
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()); } }); }
Example #5
Source File: PropertyMapConfigurerSupportTest.java From modelmapper-spring-boot-starter with Apache License 2.0 | 6 votes |
@Bean public PropertyMapConfigurerSupport<User, UserDto> userMapping() { return new PropertyMapConfigurerSupport<User, UserDto>() { @Override public PropertyMap<User, UserDto> mapping() { return new PropertyMap<User, UserDto>() { @Override protected void configure() { map().setFirstName(source.getName()); map().setLastName(source.getName()); } }; } }; }
Example #6
Source File: GenericConverter.java From heimdall with Apache License 2.0 | 5 votes |
public static <T, E> void convertWithMapping(T source, E destination, PropertyMap<T, E> mapping) { if (source != null && destination != null) { ModelMapper modelMapper = new ModelMapper(); modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); modelMapper.addMappings(mapping); modelMapper.map(source, destination); } }
Example #7
Source File: OrderMapper.java From research-graphql with MIT License | 5 votes |
public OrderMapper() { mapper = new ModelMapper(); // use strict to prevent over eager matching (happens with ID fields) mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); // create PropertyMap<source,target> here and add to mapper mapper.addMappings(new PropertyMap<OrderForm, OrderDto>() { @Override protected void configure() { } }); mapper.addMappings(new PropertyMap<OrderDto, OrderForm>() { @Override protected void configure() { } }); mapper.addMappings(new PropertyMap<OrderItemDto, OrderItem>() { @Override protected void configure() { } }); // need to add the parent link to jpa order items (as these don't exist in dto form) mapper.getTypeMap(OrderDto.class, OrderForm.class) .setPostConverter(context -> { OrderForm target = context.getDestination(); log.info("post-converter fixing OrderItem parent links {}", target); if (target.getItems() != null) { target.getItems().stream().forEach((item) -> item.setOrder(target)); } return target; }); }
Example #8
Source File: UserMapper.java From research-graphql with MIT License | 5 votes |
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 }
Example #9
Source File: ModelMapperAutoConfiguration.java From building-microservices with Apache License 2.0 | 5 votes |
public ModelMapperAutoConfiguration(ModelMapperProperties properties, ObjectProvider<List<PropertyMap<?, ?>>> mappings, ObjectProvider<List<Converter<?, ?>>> converters) { this.properties = properties; this.mappings = mappings.getIfAvailable(); this.converters = converters.getIfAvailable(); }
Example #10
Source File: ModelMapperOrderedConfigurerTest.java From modelmapper-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override public PropertyMap<String, Object> mapping() { return new PropertyMap<String, Object>() { @Override protected void configure() { // DO SOMETHING } }; }
Example #11
Source File: ModelMapperOrderedConfigurerTest.java From modelmapper-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override public PropertyMap<String, Object> mapping() { return new PropertyMap<String, Object>() { @Override protected void configure() { // DO SOMETHING } }; }
Example #12
Source File: PropertyMapConfigurerSupport.java From modelmapper-spring-boot-starter with Apache License 2.0 | 2 votes |
/** * Allows to specify the specific property mapping between two different objects. * * @return the property map */ public abstract PropertyMap<S, D> mapping();