mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-06 17:18:43 +08:00
commit
3097791c98
@ -188,7 +188,7 @@ public class User {
|
||||
|
||||
```xml
|
||||
<properties>
|
||||
<mapstruct-plus.version>1.4.0</mapstruct-plus.version>
|
||||
<mapstruct-plus.version>1.4.1</mapstruct-plus.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@ -2,7 +2,9 @@ import { defineUserConfig } from "vuepress";
|
||||
import type { DefaultThemeOptions } from "vuepress";
|
||||
import recoTheme from "vuepress-theme-reco";
|
||||
import { themeConfig } from './config/index'
|
||||
import { umamiAnalyticsPlugin } from 'vuepress-plugin-umami-analytics'
|
||||
import { sitemapPlugin } from '@vuepress/plugin-sitemap'
|
||||
import { webpackBundler } from '@vuepress/bundler-webpack'
|
||||
import { viteBundler } from '@vuepress/bundler-vite'
|
||||
|
||||
export default defineUserConfig({
|
||||
locales: {
|
||||
@ -37,9 +39,9 @@ export default defineUserConfig({
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
umamiAnalyticsPlugin({
|
||||
id: '50be7a94-e1d7-4d49-a8db-67b17acaa0b3',
|
||||
src: 'https://114.115.147.1/script.js'
|
||||
})
|
||||
]
|
||||
sitemapPlugin({
|
||||
hostname: 'mapstruct.plus'
|
||||
}),
|
||||
],
|
||||
bundler: webpackBundler(),
|
||||
});
|
||||
|
||||
@ -11,8 +11,8 @@ bannerBrand:
|
||||
description: 可能是最简单最强大的Java Bean转换工具
|
||||
tagline: Mapstruct Plus 是 Mapstruct 的增强工具,在 Mapstruct 的基础上,实现了自动生成 Mapper 接口的功能,并强化了部分功能,使 Java 类型转换更加便捷、优雅。
|
||||
buttons:
|
||||
- { text: 快速开始, link: '/introduction/quick-start' }
|
||||
- { text: '常见问题', link: '/guide/faq', type: 'plain' }
|
||||
- { text: 快速开始, link: '/introduction/quick-start.html' }
|
||||
- { text: '常见问题', link: '/guide/faq.html', type: 'plain' }
|
||||
socialLinks:
|
||||
- { icon: 'LogoGithub', link: 'https://github.com/vuepress-reco/vuepress-theme-reco' }
|
||||
isShowTitleInHome: true
|
||||
@ -62,18 +62,31 @@ footer:
|
||||
<dependency>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
|
||||
<version>1.4.0-R1</version>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
- gradle
|
||||
|
||||
```groovy
|
||||
implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.4.0-R1'
|
||||
implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.4.1'
|
||||
```
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 1.4.1
|
||||
|
||||
- feat: `AutoMapper` 注解增加 `mapperNameSuffix` 属性,支持配置生成的转换接口名称增加后缀,默认规则下生成的反向转换接口同时生效;
|
||||
- feat : 适配 `Mapper` 注解的 `unmappedSourcePolicy`、`unmappedTargetPolicy`、`typeConversionPolicy`、`collectionMappingStrategy`、`nullValueMappingStrategy`、`nullValueIterableMappingStrategy`、`nullValuePropertyMappingStrategy`、`nullValueCheckStrategy`、`mappingControl` 属性;
|
||||
- feat : 适配 `Mapping` 注解的 `constant`、`qualifiedBy`、`nullValueCheckStrategy`、`nullValuePropertyMappingStrategy`、`mappingControl`;
|
||||
- feat : 适配 MapStruct 配置的 `typeConversionPolicy`、`collectionMappingStrategy`、`nullValueIterableMappingStrategy`、`nullValueMapMappingStrategy`、`nullValueCheckStrategy`、`mappingControl`、`unexpectedValueMappingException`、`suppressTimestampInGenerated` 属性;
|
||||
- fix : 适配同一个模块中同类不同包生成类名冲突的问题;
|
||||
- feat : `AutoMapping` 注解增加 `reverseConvertGenerate`,控制是否生成反向转换逻辑,适配更加复杂的应用场景;
|
||||
- fix : 修复 `targetClass` 同时配置父类和子类时,转换规则冲突的问题;
|
||||
- fix : 修复不同模块配置类、代理类类名冲突的问题;
|
||||
- feat : `AutoMapper` 增加 `useEnums` 属性,支持手动配置转换时需要的枚举,解决跨模块枚举无法自动转换的问题;
|
||||
- 优化转换接口生成逻辑;
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- **优化复杂对象转换逻辑,占用元空间更小!性能更快!**
|
||||
@ -82,6 +95,12 @@ implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-s
|
||||
- [feature#63](https://github.com/linpeilie/mapstruct-plus/pull/63)`AutoMapping`、`ReverseAutoMapping` 支持 `qualifiedByName`、`conditionQualifiedByName` 和 `dependsOn` 属性
|
||||
- [issue#I93Z2Z](https://gitee.com/easii/mapstruct-plus/issues/I93Z2Z)`AutoMappings` 支持配置在方法上面
|
||||
|
||||
> 升级 1.4.0 注意事项:
|
||||
> - 1.4.0 及以后的版本,复杂对象比较依赖项目中生成的 `ConvertMapperAdapter`,
|
||||
> 在多模块下,由于类加载机制只会加载一个的原因,可能会导致 [`NoSuchMethodError`](/guide/faq.html) 的异常,
|
||||
> 当然,这个问题在之前也会有,几率可能低一些,所以多模块下,务必配置 `adapterPackage` 来避免该问题。
|
||||
> - Map 与对象的转换,还是依赖 hutool 中的类转换实现,如果需要该功能,需要额外引入 `hutool-core` 依赖包。
|
||||
|
||||
### 1.3.6
|
||||
|
||||
- 兼容内部类转换
|
||||
@ -89,12 +108,6 @@ implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-s
|
||||
- [issue#I8QPRO](https://gitee.com/easii/mapstruct-plus/issues/I8QPRO) : 框架自动生成的 AutoMapperConfig 和 AutoMapMapper 包和类名支持配置
|
||||
- [issue#I8T7EF](https://gitee.com/easii/mapstruct-plus/issues/I8T7EF) : 支持在父类中配置的 AutoMapping 注解
|
||||
|
||||
|
||||
### 1.3.5
|
||||
|
||||
- AutoMapping、ReverseAutoMapping 支持配置在方法上面;
|
||||
- AutoMapping、ReverseAutoMapping 支持 defaultExpression 和 conditionExpression 属性
|
||||
|
||||
……
|
||||
|
||||
## 代码仓库
|
||||
|
||||
@ -11,8 +11,8 @@ bannerBrand:
|
||||
description: Probably the simplest and most powerful Java Bean transformation tool
|
||||
tagline: MapStructPlus is an enhancement tool of MapStruct. On the basis of MapStruct, it realizes the function of automatically generating Mapper interface, and strengthens some functions, making Java type conversion more convenient and elegant.
|
||||
buttons:
|
||||
- { text: Quick Start, link: '/en/introduction/quick-start' }
|
||||
- { text: 'FAQ', link: '/en/guide/faq', type: 'plain' }
|
||||
- { text: Quick Start, link: '/en/introduction/quick-start.html' }
|
||||
- { text: 'FAQ', link: '/en/guide/faq.html', type: 'plain' }
|
||||
socialLinks:
|
||||
- { icon: 'LogoGithub', link: 'https://github.com/vuepress-reco/vuepress-theme-reco' }
|
||||
isShowTitleInHome: true
|
||||
@ -58,18 +58,37 @@ fotter:
|
||||
<dependency>
|
||||
<groupId>io.github.linpeilie</groupId>
|
||||
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
|
||||
<version>1.4.0-R1</version>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
- gradle
|
||||
|
||||
```groovy
|
||||
implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.4.0-R1'
|
||||
implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-starter', version: '1.4.0'
|
||||
```
|
||||
|
||||
## Change Log
|
||||
|
||||
### 1.4.1
|
||||
|
||||
Sure, here is the translated update document:
|
||||
|
||||
---
|
||||
|
||||
### Updates
|
||||
|
||||
- **feat**: Added the `mapperNameSuffix` attribute to the `AutoMapper` annotation. This supports adding a suffix to the generated conversion interface name, and the reverse conversion interface will be effective under the default rules.
|
||||
- **feat**: Adapted the `Mapper` annotation to support the following attributes: `unmappedSourcePolicy`, `unmappedTargetPolicy`, `typeConversionPolicy`, `collectionMappingStrategy`, `nullValueMappingStrategy`, `nullValueIterableMappingStrategy`, `nullValuePropertyMappingStrategy`, `nullValueCheckStrategy`, and `mappingControl`.
|
||||
- **feat**: Adapted the `Mapping` annotation to support the following attributes: `constant`, `qualifiedBy`, `nullValueCheckStrategy`, `nullValuePropertyMappingStrategy`, and `mappingControl`.
|
||||
- **feat**: Adapted MapStruct configuration to support the following attributes: `typeConversionPolicy`, `collectionMappingStrategy`, `nullValueIterableMappingStrategy`, `nullValueMapMappingStrategy`, `nullValueCheckStrategy`, `mappingControl`, `unexpectedValueMappingException`, and `suppressTimestampInGenerated`.
|
||||
- **fix**: Resolved the issue of class name conflicts generated in different packages within the same module.
|
||||
- **feat**: Added the `reverseConvertGenerate` attribute to the `AutoMapping` annotation to control whether to generate reverse conversion logic, adapting to more complex application scenarios.
|
||||
- **fix**: Fixed the issue of conversion rule conflicts when both parent and child classes are configured in `targetClass`.
|
||||
- **fix**: Resolved class name conflicts of configuration classes and proxy classes in different modules.
|
||||
- **feat**: Added the `useEnums` attribute to `AutoMapper`, supporting manual configuration of required enums for conversion, solving the issue of automatic conversion of enums across modules.
|
||||
- Optimized the logic for generating conversion interfaces.
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- **Optimize complex object conversion logic, take up less meta-space! and faster!**
|
||||
@ -78,6 +97,14 @@ implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-s
|
||||
- [feature#63](https://github.com/linpeilie/mapstruct-plus/pull/63) `AutoMapping`、`ReverseAutoMapping` supports `qualifiedByName`,`conditionQualifiedByName`,and `dependsOn` properties.
|
||||
- [issue#I93Z2Z](https://gitee.com/easii/mapstruct-plus/issues/I93Z2Z) `AutoMappings` supports configuration on methods.
|
||||
|
||||
> Points to note for upgrading 1.4.0
|
||||
> - 1.4.0 and later versions, complex object comparisons reply on `ConvertMapperAdapter` generated in the project,
|
||||
which may cause [`NoSuchMethodError`](/guide/faq.html) exceptions under multiple modules because the Class Loading mechanism
|
||||
will load only one, of course, this problem has been around before, and the odds are probably lower,
|
||||
so be sure to configure the `adapterPackage` to avoid this problem with multiple modules.
|
||||
> - Map to object conversions still rely on class conversions in hutool, and additional `hutool-core` dependencies need to be introduced if this
|
||||
functionality is required.
|
||||
|
||||
### 1.3.6
|
||||
|
||||
- Compatible with internal class conversion.
|
||||
@ -85,11 +112,6 @@ implementation group: 'io.github.linpeilie', name: 'mapstruct-plus-spring-boot-s
|
||||
- AutoMapperConfig and AutoMapMapperConfig package and class name generated automatically by the framework support configuration.
|
||||
- Supports AutoMapping annotations configured in the parent class.
|
||||
|
||||
### 1.3.5
|
||||
|
||||
- `@AutoMapping`、`@ReversedAutoMapping` support is configured on top of methods.
|
||||
- `@AutoMapping`、`@ReverseAutoMapping` support the defaultExpression and conditionExpression properties
|
||||
|
||||
……
|
||||
|
||||
## Code Warehouse
|
||||
|
||||
@ -191,3 +191,91 @@ eg:
|
||||
- **Type**:`String`
|
||||
- **Default**:AutoMapMapperConfig
|
||||
- **Compile Parameter**:`-Amapstruct.plus.autoMapMapperConfigClassName`
|
||||
|
||||
### typeConversionPolicy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:How lossy (narrowing) conversion, for instance: long to integer should be reported.
|
||||
- **Type**:`ReportingPolicy`
|
||||
- **Optional**:
|
||||
- `IGNORE`
|
||||
- `WARN`
|
||||
- `ERROR`
|
||||
- **Default**:`IGNORE`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.typeConversionPolicy`
|
||||
|
||||
### collectionMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:The strategy to be applied when propagating the value of collection-typed properties. By default, only JavaBeans accessor methods (setters or getters) will be used, but it is also possible to invoke a corresponding adder method for each element of the source collection (e. g. orderDto.
|
||||
- **Type**:`CollectionMappingStrategy`
|
||||
- **Optional**:
|
||||
- `ACCESSOR_ONLY`
|
||||
- `SETTER_PREFERRED`
|
||||
- `ADDER_PREFERRED`
|
||||
- `TARGET_IMMUTABLE`
|
||||
- **Default**:`ACCESSOR_ONLY`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.collectionMappingStrategy`
|
||||
|
||||
### nullValueIterableMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:The strategy to be applied when null is passed as source argument value to an IterableMapping. If no strategy is configured, the strategy given via `nullValueMappingStrategy()` will be applied, using `NullValueMappingStrategy`.`RETURN_NULL` by default.
|
||||
- **Type**:`NullValueMappingStrategy`
|
||||
- **Optional**:
|
||||
- `RETURN_NULL`
|
||||
- `RETURN_DEFAULT`
|
||||
- **Default**:`RETURN_NULL`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.nullValueIterableMappingStrategy`
|
||||
|
||||
### nullValueMapMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:he strategy to be applied when null is passed as source argument value to a MapMapping. If no strategy is configured, the strategy given via `nullValueMappingStrategy()` will be applied, using `NullValueMappingStrategy`.`RETURN_NULL` by default.
|
||||
- **Type**:`NullValueMappingStrategy`
|
||||
- **Optional**:
|
||||
- `RETURN_NULL`
|
||||
- `RETURN_DEFAULT`
|
||||
- **Default**:`RETURN_NULL`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.nullValueMapMappingStrategy`
|
||||
|
||||
### nullValueCheckStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:Determines when to include a null check on the source property value of a bean mapping.
|
||||
- **Type**:`NullValueCheckStrategy`
|
||||
- **Optional**:
|
||||
- `ON_IMPLICIT_CONVERSION`
|
||||
- `ALWAYS`
|
||||
- **Default**:`ON_IMPLICIT_CONVERSION`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.nullValueCheckStrategy`
|
||||
|
||||
### mappingControl
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:Allows detailed control over the mapping process.
|
||||
- **Type**:`Class`
|
||||
- **Default**:`MappingControl.class`
|
||||
|
||||
### unexpectedValueMappingException
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:Exception that should be thrown by the generated code if no mapping matches for enums. If no exception is configured, IllegalArgumentException will be used by default.
|
||||
- **Type**:`Class`
|
||||
- **Default**:`IllegalArgumentException.class`
|
||||
|
||||
### suppressTimestampInGenerated
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **Description**:Flag indicating whether the addition of a time stamp in the @Generated annotation should be suppressed. i. e. not be added. The method overrides the flag set through an annotation processor option.
|
||||
- **Type**:`boolean`
|
||||
- **Default**:`false`
|
||||
- **Compile Parameter**:`-Amapstruct.plus.suppressTimestampInGenerated`
|
||||
@ -75,3 +75,13 @@ public void enumMapTest() {
|
||||
}
|
||||
```
|
||||
|
||||
### Cross-Module Support
|
||||
|
||||
When enums and the types they are used with are not in the same module, they cannot be automatically converted and require specified dependency relationships.
|
||||
|
||||
In the `AutoMapper` annotation, you can specify the enum class list needed for the current conversion relationship through the `useEnums` attribute. These enums need to be annotated with `AutoEnumMapper`.
|
||||
|
||||
> This feature is supported starting from version 1.4.1.
|
||||
|
||||
It is important to note that when two classes are in the same module, specification is not required, and they can be automatically converted. This feature mainly addresses the issue of inability to automatically convert between different modules.
|
||||
|
||||
|
||||
@ -6,6 +6,19 @@ category:
|
||||
description: MapStructPlus release log
|
||||
---
|
||||
|
||||
### 1.4.1
|
||||
|
||||
- **feat**: Added the `mapperNameSuffix` attribute to the `AutoMapper` annotation. This supports adding a suffix to the generated conversion interface name, and the reverse conversion interface will be effective under the default rules.
|
||||
- **feat**: Adapted the `Mapper` annotation to support the following attributes: `unmappedSourcePolicy`, `unmappedTargetPolicy`, `typeConversionPolicy`, `collectionMappingStrategy`, `nullValueMappingStrategy`, `nullValueIterableMappingStrategy`, `nullValuePropertyMappingStrategy`, `nullValueCheckStrategy`, and `mappingControl`.
|
||||
- **feat**: Adapted the `Mapping` annotation to support the following attributes: `constant`, `qualifiedBy`, `nullValueCheckStrategy`, `nullValuePropertyMappingStrategy`, and `mappingControl`.
|
||||
- **feat**: Adapted MapStruct configuration to support the following attributes: `typeConversionPolicy`, `collectionMappingStrategy`, `nullValueIterableMappingStrategy`, `nullValueMapMappingStrategy`, `nullValueCheckStrategy`, `mappingControl`, `unexpectedValueMappingException`, and `suppressTimestampInGenerated`.
|
||||
- **fix**: Resolved the issue of class name conflicts generated in different packages within the same module.
|
||||
- **feat**: Added the `reverseConvertGenerate` attribute to the `AutoMapping` annotation to control whether to generate reverse conversion logic, adapting to more complex application scenarios.
|
||||
- **fix**: Fixed the issue of conversion rule conflicts when both parent and child classes are configured in `targetClass`.
|
||||
- **fix**: Resolved class name conflicts of configuration classes and proxy classes in different modules.
|
||||
- **feat**: Added the `useEnums` attribute to `AutoMapper`, supporting manual configuration of required enums for conversion, solving the issue of automatic conversion of enums across modules.
|
||||
- Optimized the logic for generating conversion interfaces.
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- **Optimize complex object conversion logic, take up less meta-space! and faster!**
|
||||
@ -14,6 +27,14 @@ description: MapStructPlus release log
|
||||
- [feature#63](https://github.com/linpeilie/mapstruct-plus/pull/63) `AutoMapping`、`ReverseAutoMapping` supports `qualifiedByName`,`conditionQualifiedByName`,and `dependsOn` properties.
|
||||
- [issue#I93Z2Z](https://gitee.com/easii/mapstruct-plus/issues/I93Z2Z) `AutoMappings` supports configuration on methods.
|
||||
|
||||
> Points to note for upgrading 1.4.0
|
||||
> - 1.4.0 and later versions, complex object comparisons reply on `ConvertMapperAdapter` generated in the project,
|
||||
which may cause [`NoSuchMethodError`](/guide/faq.html) exceptions under multiple modules because the Class Loading mechanism
|
||||
will load only one, of course, this problem has been around before, and the odds are probably lower,
|
||||
so be sure to configure the `adapterPackage` to avoid this problem with multiple modules.
|
||||
> - Map to object conversions still rely on class conversions in hutool, and additional `hutool-core` dependencies need to be introduced if this
|
||||
functionality is required.
|
||||
|
||||
### 1.3.6
|
||||
|
||||
- Compatible with internal class conversion.
|
||||
|
||||
@ -188,3 +188,91 @@ public class MapStructPlusConfiguration {
|
||||
- **类型**:`String`
|
||||
- **默认值**:AutoMapMapperConfig
|
||||
- **对应编译参数**:`-Amapstruct.plus.autoMapMapperConfigClassName`
|
||||
|
||||
### typeConversionPolicy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:有损转换的处理策略,例如:long 转换为 int
|
||||
- **类型**:`ReportingPolicy`
|
||||
- **支持配置项**:
|
||||
- `IGNORE`
|
||||
- `WARN`
|
||||
- `ERROR`
|
||||
- **默认值**:`IGNORE`
|
||||
- **对应编译参数**:`-Amapstruct.plus.typeConversionPolicy`
|
||||
|
||||
### collectionMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:转换列表集合属性时的策略。
|
||||
- **类型**:`CollectionMappingStrategy`
|
||||
- **支持配置项**:
|
||||
- `ACCESSOR_ONLY`
|
||||
- `SETTER_PREFERRED`
|
||||
- `ADDER_PREFERRED`
|
||||
- `TARGET_IMMUTABLE`
|
||||
- **默认值**:`ACCESSOR_ONLY`
|
||||
- **对应编译参数**:`-Amapstruct.plus.collectionMappingStrategy`
|
||||
|
||||
### nullValueIterableMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:当将 `null` 作为源参数值传递给 `IterableMapping` 时要应用的策略。如果未配置策略,则将应用通过 `nullValueMappingStrategy()` 给出的策略。
|
||||
- **类型**:`NullValueMappingStrategy`
|
||||
- **支持配置项**:
|
||||
- `RETURN_NULL`
|
||||
- `RETURN_DEFAULT`
|
||||
- **默认值**:`RETURN_NULL`
|
||||
- **对应编译参数**:`-Amapstruct.plus.nullValueIterableMappingStrategy`
|
||||
|
||||
### nullValueMapMappingStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:当将 `null` 作为源参数值传递给 `MapMapping` 时要应用的策略。如果未配置策略,则将应用通过 `nullValueMappingStrategy()` 给出的策略。
|
||||
- **类型**:`NullValueMappingStrategy`
|
||||
- **支持配置项**:
|
||||
- `RETURN_NULL`
|
||||
- `RETURN_DEFAULT`
|
||||
- **默认值**:`RETURN_NULL`
|
||||
- **对应编译参数**:`-Amapstruct.plus.nullValueMapMappingStrategy`
|
||||
|
||||
### nullValueCheckStrategy
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:确定何时对 bean 映射的源属性值进行 null 检查。
|
||||
- **类型**:`NullValueCheckStrategy`
|
||||
- **支持配置项**:
|
||||
- `ON_IMPLICIT_CONVERSION`
|
||||
- `ALWAYS`
|
||||
- **默认值**:`ON_IMPLICIT_CONVERSION`
|
||||
- **对应编译参数**:`-Amapstruct.plus.nullValueCheckStrategy`
|
||||
|
||||
### mappingControl
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:允许对映射过程进行详细控制。
|
||||
- **类型**:`Class`
|
||||
- **默认值**:`MappingControl.class`
|
||||
|
||||
### unexpectedValueMappingException
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:如果枚举没有匹配的映射,则生成的代码应抛出异常。如果没有配置异常,则默认使用 IllegalArgumentException 。
|
||||
- **类型**:`Class`
|
||||
- **默认值**:`IllegalArgumentException.class`
|
||||
|
||||
### suppressTimestampInGenerated
|
||||
|
||||
> since `1.4.1`
|
||||
|
||||
- **说明**:标识是否应在 `@Generated` 注释中添加时间戳
|
||||
- **类型**:`boolean`
|
||||
- **默认值**:`false`
|
||||
- **对应编译参数**:`-Amapstruct.plus.suppressTimestampInGenerated`
|
||||
@ -6,6 +6,8 @@ category:
|
||||
description: MapStructPlus Map转为对象 map convert to class
|
||||
---
|
||||
|
||||
## 枚举自动转换
|
||||
|
||||
> 当前特性从 1.2.2 开始支持
|
||||
|
||||
当需要进行枚举转换时(例如枚举转换为编码值,或者由编码转换为枚举),可以在目标枚举添加 `@AutoEnumMapper` 注解,
|
||||
@ -73,3 +75,12 @@ public void enumMapTest() {
|
||||
}
|
||||
```
|
||||
|
||||
## 跨模块支持
|
||||
|
||||
当枚举与要使用的类型,不在同一个模块(module)中时,并不能自动转换,需要指定依赖关系。
|
||||
|
||||
在 `AutoMapper` 注解中,可以通过属性 `useEnums` 来指定,当前转换关系,需要依赖的枚举类列表。这些枚举需要被 `AutoEnumMapper`注解。
|
||||
|
||||
> 该特性从 1.4.1 开始支持
|
||||
|
||||
需要注意的是,当两个类在同一个模块(module)中,无需指定,可以自动转换。当前特性主要解决跨模块之间不能自动转换的问题。
|
||||
|
||||
@ -6,6 +6,19 @@ category:
|
||||
description: MapStructPlus release log
|
||||
---
|
||||
|
||||
### 1.4.1
|
||||
|
||||
- feat: `AutoMapper` 注解增加 `mapperNameSuffix` 属性,支持配置生成的转换接口名称增加后缀,默认规则下生成的反向转换接口同时生效;
|
||||
- feat : 适配 `Mapper` 注解的 `unmappedSourcePolicy`、`unmappedTargetPolicy`、`typeConversionPolicy`、`collectionMappingStrategy`、`nullValueMappingStrategy`、`nullValueIterableMappingStrategy`、`nullValuePropertyMappingStrategy`、`nullValueCheckStrategy`、`mappingControl` 属性;
|
||||
- feat : 适配 `Mapping` 注解的 `constant`、`qualifiedBy`、`nullValueCheckStrategy`、`nullValuePropertyMappingStrategy`、`mappingControl`;
|
||||
- feat : 适配 MapStruct 配置的 `typeConversionPolicy`、`collectionMappingStrategy`、`nullValueIterableMappingStrategy`、`nullValueMapMappingStrategy`、`nullValueCheckStrategy`、`mappingControl`、`unexpectedValueMappingException`、`suppressTimestampInGenerated` 属性;
|
||||
- fix : 适配同一个模块中同类不同包生成类名冲突的问题;
|
||||
- feat : `AutoMapping` 注解增加 `reverseConvertGenerate`,控制是否生成反向转换逻辑,适配更加复杂的应用场景;
|
||||
- fix : 修复 `targetClass` 同时配置父类和子类时,转换规则冲突的问题;
|
||||
- fix : 修复不同模块配置类、代理类类名冲突的问题;
|
||||
- feat : `AutoMapper` 增加 `useEnums` 属性,支持手动配置转换时需要的枚举,解决跨模块枚举无法自动转换的问题;
|
||||
- 优化转换接口生成逻辑;
|
||||
|
||||
### 1.4.0
|
||||
|
||||
- **优化复杂对象转换逻辑,占用元空间更小!性能更快!**
|
||||
@ -14,6 +27,14 @@ description: MapStructPlus release log
|
||||
- [feature#63](https://github.com/linpeilie/mapstruct-plus/pull/63)`AutoMapping`、`ReverseAutoMapping` 支持 `qualifiedByName`、`conditionQualifiedByName` 和 `dependsOn` 属性
|
||||
- [issue#I93Z2Z](https://gitee.com/easii/mapstruct-plus/issues/I93Z2Z)`AutoMappings` 支持配置在方法上面
|
||||
|
||||
|
||||
> 升级 1.4.0 注意事项:
|
||||
> - 1.4.0 及以后的版本,复杂对象比较依赖项目中生成的 `ConvertMapperAdapter`,
|
||||
在多模块下,由于类加载机制只会加载一个的原因,可能会导致 [`NoSuchMethodError`](/guide/faq.html) 的异常,
|
||||
当然,这个问题在之前也会有,几率可能低一些,所以多模块下,务必配置 `adapterPackage` 来避免该问题。
|
||||
> - Map 与对象的转换,还是依赖 hutool 中的类转换实现,如果需要该功能,需要额外引入 `hutool-core` 依赖包。
|
||||
|
||||
|
||||
### 1.3.6
|
||||
|
||||
- 兼容内部类转换
|
||||
|
||||
@ -18,9 +18,10 @@
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mapstruct.version>1.5.1.Final</mapstruct.version>
|
||||
<mapstruct-plus.version>1.4.0</mapstruct-plus.version>
|
||||
<mapstruct-plus.version>1.4.1</mapstruct-plus.version>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<hutool.version>5.8.26</hutool.version>
|
||||
<guava.version>32.1.3-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -50,6 +51,11 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@ -50,6 +50,10 @@
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package io.github.linpeilie;
|
||||
|
||||
import io.github.linpeilie.annotations.MapperConfig;
|
||||
import org.mapstruct.Builder;
|
||||
|
||||
@MapperConfig(adapterClassName = "DemoConvertMapperAdapter",
|
||||
adapterPackage = "io.github.linpeilie.adapter",
|
||||
mapAdapterClassName = "DemoMapConvertMapperAdapter",
|
||||
autoConfigPackage = "cn.easii",
|
||||
autoMapperConfigClassName = "EasiiAutoMapperConfig",
|
||||
autoMapMapperConfigClassName = "EasiiAutoMapMapperConfig")
|
||||
autoMapMapperConfigClassName = "EasiiAutoMapMapperConfig",
|
||||
builder = @Builder(disableBuilder = false))
|
||||
public class MapStructPlusConfiguration {
|
||||
}
|
||||
|
||||
@ -13,6 +13,9 @@ public class Titles {
|
||||
if ("One Hundred Years of Solitude".equals(title)) {
|
||||
return "Cent ans de solitude";
|
||||
}
|
||||
if ("Default".equals(title)) {
|
||||
return null;
|
||||
}
|
||||
return "Inconnu et inconnu";
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class NoProperties {
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@AutoMapper(target = NoProperties.class)
|
||||
public class WithProperties {
|
||||
|
||||
private String string;
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
public void setString(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.array;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = ScientistDto.class)
|
||||
public class Scientist {
|
||||
|
||||
//CHECKSTYLE:OFF
|
||||
public String[] publicPublications;
|
||||
public String[] publicPublicationYears;
|
||||
//CHECKSTYLE:ON
|
||||
private String name;
|
||||
private String[] publications;
|
||||
private String[] publicationYears;
|
||||
|
||||
public Scientist(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getPublications() {
|
||||
return publications;
|
||||
}
|
||||
|
||||
public void setPublications(String[] publications) {
|
||||
this.publications = publications;
|
||||
}
|
||||
|
||||
public String[] getPublicationYears() {
|
||||
return publicationYears;
|
||||
}
|
||||
|
||||
public void setPublicationYears(String[] publicationYears) {
|
||||
this.publicationYears = publicationYears;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.array;
|
||||
|
||||
public class ScientistDto {
|
||||
|
||||
//CHECKSTYLE:OFF
|
||||
public String[] publicPublications;
|
||||
public int[] publicPublicationYears;
|
||||
//CHECKSTYLE:ON
|
||||
|
||||
private String name;
|
||||
private String[] publications;
|
||||
private int[] publicationYears;
|
||||
|
||||
public ScientistDto() {
|
||||
}
|
||||
|
||||
public ScientistDto(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getPublications() {
|
||||
return publications;
|
||||
}
|
||||
|
||||
public void setPublications(String[] publications) {
|
||||
this.publications = publications;
|
||||
}
|
||||
|
||||
public int[] getPublicationYears() {
|
||||
return publicationYears;
|
||||
}
|
||||
|
||||
public void setPublicationYears(int[] publicationYears) {
|
||||
this.publicationYears = publicationYears;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.bool;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = PersonDto.class, uses = YesNoMapper.class, reverseConvertGenerate = false)
|
||||
public class Person {
|
||||
|
||||
private Boolean married;
|
||||
private Boolean engaged;
|
||||
private YesNo divorced;
|
||||
private YesNo widowed;
|
||||
|
||||
public Boolean isMarried() {
|
||||
return married;
|
||||
}
|
||||
|
||||
public void setMarried(Boolean married) {
|
||||
this.married = married;
|
||||
}
|
||||
|
||||
// START: please note: deliberately ordered, first getEngaged, then isEngaged.
|
||||
public Boolean getEngaged() {
|
||||
return engaged;
|
||||
}
|
||||
|
||||
public Boolean isEngaged() {
|
||||
return engaged != null && !engaged;
|
||||
}
|
||||
// END
|
||||
|
||||
public void setEngaged(Boolean engaged) {
|
||||
this.engaged = engaged;
|
||||
}
|
||||
|
||||
public YesNo getDivorced() {
|
||||
return divorced;
|
||||
}
|
||||
|
||||
public void setDivorced(YesNo divorced) {
|
||||
this.divorced = divorced;
|
||||
}
|
||||
|
||||
public YesNo getWidowed() {
|
||||
return widowed;
|
||||
}
|
||||
|
||||
public void setWidowed(YesNo widowed) {
|
||||
this.widowed = widowed;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.bool;
|
||||
|
||||
public class PersonDto {
|
||||
|
||||
private String married;
|
||||
private String engaged;
|
||||
private String divorced;
|
||||
private Boolean widowed;
|
||||
|
||||
public String getMarried() {
|
||||
return married;
|
||||
}
|
||||
|
||||
public void setMarried(String married) {
|
||||
this.married = married;
|
||||
}
|
||||
|
||||
public String getEngaged() {
|
||||
return engaged;
|
||||
}
|
||||
|
||||
public void setEngaged(String engaged) {
|
||||
this.engaged = engaged;
|
||||
}
|
||||
|
||||
public String getDivorced() {
|
||||
return divorced;
|
||||
}
|
||||
|
||||
public void setDivorced(String divorced) {
|
||||
this.divorced = divorced;
|
||||
}
|
||||
|
||||
public Boolean getWidowed() {
|
||||
return widowed;
|
||||
}
|
||||
|
||||
public void setWidowed(Boolean widowed) {
|
||||
this.widowed = widowed;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.bool;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class YesNo {
|
||||
private boolean yes;
|
||||
|
||||
public YesNo(boolean yes) {
|
||||
this.yes = yes;
|
||||
}
|
||||
|
||||
public boolean isYes() {
|
||||
return yes;
|
||||
}
|
||||
|
||||
public void setYes(boolean yes) {
|
||||
this.yes = yes;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.bool;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public class YesNoMapper {
|
||||
public String toString(YesNo yesNo) {
|
||||
if ( null != yesNo && yesNo.isYes() ) {
|
||||
return "yes";
|
||||
}
|
||||
|
||||
return "no";
|
||||
}
|
||||
|
||||
public boolean toBool(YesNo yesNo) {
|
||||
return ( null != yesNo && yesNo.isYes() );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractBuilder;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public abstract class AbstractImmutableProduct {
|
||||
|
||||
private final String name;
|
||||
|
||||
public AbstractImmutableProduct(AbstractProductBuilder<?> builder) {
|
||||
this.name = builder.name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractBuilder;
|
||||
|
||||
public abstract class AbstractProductBuilder<T extends AbstractImmutableProduct> {
|
||||
|
||||
protected String name;
|
||||
|
||||
public AbstractProductBuilder<T> name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract T build();
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractBuilder;
|
||||
|
||||
public class ImmutableProduct extends AbstractImmutableProduct {
|
||||
|
||||
private final Integer price;
|
||||
|
||||
public ImmutableProduct(ImmutableProductBuilder builder) {
|
||||
super( builder );
|
||||
this.price = builder.price;
|
||||
}
|
||||
|
||||
public static ImmutableProductBuilder builder() {
|
||||
return new ImmutableProductBuilder();
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public static class ImmutableProductBuilder extends AbstractProductBuilder<ImmutableProduct> {
|
||||
private Integer price;
|
||||
|
||||
public ImmutableProductBuilder price(Integer price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableProduct build() {
|
||||
return new ImmutableProduct( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractBuilder;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = ImmutableProduct.class)
|
||||
public class ProductDto {
|
||||
private String name;
|
||||
private Integer price;
|
||||
|
||||
public ProductDto() {
|
||||
}
|
||||
|
||||
public ProductDto(String name, Integer price) {
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Integer price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public interface Child {
|
||||
String getName();
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = ImmutableChild.class)
|
||||
public class ChildSource {
|
||||
private String name;
|
||||
|
||||
public ChildSource() {
|
||||
}
|
||||
|
||||
public ChildSource(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public class ImmutableChild implements Child {
|
||||
private final String name;
|
||||
|
||||
private ImmutableChild(Builder builder) {
|
||||
this.name = builder.name;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String name;
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImmutableChild build() {
|
||||
return new ImmutableChild( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public class ImmutableParent implements Parent<ImmutableChild> {
|
||||
private final int count;
|
||||
private final ImmutableChild child;
|
||||
private final Child nonGenericChild;
|
||||
|
||||
public ImmutableParent(Builder builder) {
|
||||
this.count = builder.count;
|
||||
this.child = builder.child;
|
||||
this.nonGenericChild = builder.nonGenericChild;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Child getNonGenericChild() {
|
||||
return nonGenericChild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableChild getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private int count;
|
||||
private ImmutableChild child;
|
||||
private Child nonGenericChild;
|
||||
|
||||
public Builder count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nonGenericChild(Child nonGenericChild) {
|
||||
this.nonGenericChild = nonGenericChild;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder child(ImmutableChild child) {
|
||||
this.child = child;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImmutableParent build() {
|
||||
return new ImmutableParent( this );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public class MutableChild implements Child {
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public class MutableParent implements Parent<ImmutableChild> {
|
||||
private int count;
|
||||
private ImmutableChild child;
|
||||
private Child nonGenericChild;
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableChild getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(ImmutableChild child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Child getNonGenericChild() {
|
||||
return nonGenericChild;
|
||||
}
|
||||
|
||||
public void setNonGenericChild(Child nonGenericChild) {
|
||||
this.nonGenericChild = nonGenericChild;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
public interface Parent<T extends Child> {
|
||||
int getCount();
|
||||
|
||||
T getChild();
|
||||
|
||||
Child getNonGenericChild();
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.builder.abstractGenericTarget;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = ImmutableParent.class),
|
||||
@AutoMapper(target = MutableParent.class)
|
||||
})
|
||||
public class ParentSource {
|
||||
private int count;
|
||||
private ChildSource child;
|
||||
private ChildSource nonGenericChild;
|
||||
|
||||
public ChildSource getNonGenericChild() {
|
||||
return nonGenericChild;
|
||||
}
|
||||
|
||||
public void setNonGenericChild(ChildSource nonGenericChild) {
|
||||
this.nonGenericChild = nonGenericChild;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public ChildSource getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public void setChild(ChildSource child) {
|
||||
this.child = child;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.factory;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ObjectFactory;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Component
|
||||
public class BuilderFactoryMapper {
|
||||
|
||||
@ObjectFactory
|
||||
public Person.PersonBuilder personBuilder() {
|
||||
return new Person.PersonBuilder( "Factory with @ObjectFactory" );
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.builder.factory;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@Component
|
||||
public class BuilderImplicitFactoryMapper {
|
||||
|
||||
public ImplicitPerson.PersonBuilder personBuilder() {
|
||||
return new ImplicitPerson.PersonBuilder("Implicit Factory");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package io.github.linpeilie.me.builder.factory;
|
||||
|
||||
public class ImplicitPerson {
|
||||
|
||||
private final String name;
|
||||
private final String source;
|
||||
|
||||
protected ImplicitPerson(ImplicitPerson.PersonBuilder builder) {
|
||||
this.name = builder.name;
|
||||
this.source = builder.source;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public static ImplicitPerson.PersonBuilder builder() {
|
||||
throw new UnsupportedOperationException( "Factory should be used" );
|
||||
}
|
||||
|
||||
public static class PersonBuilder {
|
||||
private String name;
|
||||
private final String source;
|
||||
|
||||
public PersonBuilder(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public ImplicitPerson.PersonBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ImplicitPerson build() {
|
||||
return new ImplicitPerson( this );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.factory;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class Person {
|
||||
|
||||
private final String name;
|
||||
private final String source;
|
||||
|
||||
protected Person(PersonBuilder builder) {
|
||||
this.name = builder.name;
|
||||
this.source = builder.source;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public static PersonBuilder builder() {
|
||||
throw new UnsupportedOperationException( "Factory should be used" );
|
||||
}
|
||||
|
||||
public static class PersonBuilder {
|
||||
private String name;
|
||||
private final String source;
|
||||
|
||||
public PersonBuilder(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public PersonBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Person build() {
|
||||
return new Person( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.builder.factory;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = Person.class, uses = BuilderFactoryMapper.class, reverseConvertGenerate = false),
|
||||
@AutoMapper(target = ImplicitPerson.class, uses = BuilderImplicitFactoryMapper.class, reverseConvertGenerate = false),
|
||||
})
|
||||
public class PersonDto {
|
||||
|
||||
private String name;
|
||||
|
||||
public PersonDto(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.BeforeMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.TargetType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Component
|
||||
public class BaseMapper {
|
||||
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
|
||||
|
||||
@BeforeMapping
|
||||
public void noArgsBeforeMapping() {
|
||||
INVOCATIONS.add( new Invocation( "noArgsBeforeMapping" ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(SourceEnum source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAsObjectBeforeMapping(Object source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAsObjectBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(Source source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(SourceEnum source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(List<Source> source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(Map<String, Source> source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(Source source, @MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(SourceEnum source, @MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(List<Source> source, @MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(Map<String, Source> source,
|
||||
@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetAsObjectBeforeMapping(@MappingTarget Object target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAsObjectBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void noArgsAfterMapping() {
|
||||
INVOCATIONS.add( new Invocation( "noArgsAfterMapping" ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(SourceEnum source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAsObjectAfterMapping(Object source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAsObjectAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(Source source, @MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(SourceEnum source, @MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(List<Source> source, @MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(Map<String, Source> source, @MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAsObjectAfterMapping(@MappingTarget Object target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAsObjectAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public <T> void withTargetAndTargetTypeAfterMapping(@MappingTarget T target, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAndTargetTypeAfterMapping", target, targetClass ) );
|
||||
}
|
||||
|
||||
public static List<Invocation> getInvocations() {
|
||||
return INVOCATIONS;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
INVOCATIONS.clear();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.BeforeMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.mapstruct.TargetType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Component
|
||||
public class ClassContainingCallbacks {
|
||||
private static final List<Invocation> INVOCATIONS = new ArrayList<Invocation>();
|
||||
|
||||
@BeforeMapping
|
||||
public void noArgsBeforeMapping() {
|
||||
INVOCATIONS.add( new Invocation( "noArgsBeforeMapping" ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(SourceEnum source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceBeforeMapping(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
@Qualified
|
||||
public void withSourceBeforeMappingQualified(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceBeforeMappingQualified", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAsObjectBeforeMapping(Object source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAsObjectBeforeMapping", source ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(Source source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(SourceEnum source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(List<Source> source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public <T> void withSourceAndTargetTypeBeforeMapping(Map<String, Source> source, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetTypeBeforeMapping", source, targetClass ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(Source source, @MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(SourceEnum source, @MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(List<Source> source, @MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withSourceAndTargetBeforeMapping(Map<String, Source> source,
|
||||
@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetBeforeMapping", source, target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetBeforeMapping(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public void withTargetAsObjectBeforeMapping(@MappingTarget Object target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAsObjectBeforeMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void noArgsAfterMapping() {
|
||||
INVOCATIONS.add( new Invocation( "noArgsAfterMapping" ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(Source source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(SourceEnum source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(List<Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAfterMapping(Map<String, Source> source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAsObjectAfterMapping(Object source) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAsObjectAfterMapping", source ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(Source source, @MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(SourceEnum source, @MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(List<Source> source, @MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withSourceAndTargetAfterMapping(Map<String, Source> source, @MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withSourceAndTargetAfterMapping", source, target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget TargetEnum target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget Target target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget List<Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAfterMapping(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
@Qualified
|
||||
public void withTargetAfterMappingQualified(@MappingTarget Map<String, Target> target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAfterMappingQualified", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public void withTargetAsObjectAfterMapping(@MappingTarget Object target) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAsObjectAfterMapping", target ) );
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public <T> void withTargetAndTargetTypeAfterMapping(@MappingTarget T target, @TargetType Class<T> targetClass) {
|
||||
INVOCATIONS.add( new Invocation( "withTargetAndTargetTypeAfterMapping", target, targetClass ) );
|
||||
}
|
||||
|
||||
public static List<Invocation> getInvocations() {
|
||||
return INVOCATIONS;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
INVOCATIONS.clear();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public class Invocation {
|
||||
private final String methodName;
|
||||
private final String arguments;
|
||||
|
||||
public Invocation(String methodName, Object... arguments) {
|
||||
this.methodName = methodName;
|
||||
this.arguments = Arrays.toString( arguments );
|
||||
}
|
||||
|
||||
public String getMethodName() {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public String getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Invocation [methodName=" + methodName + ", arguments=" + arguments + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( ( arguments == null ) ? 0 : arguments.hashCode() );
|
||||
result = prime * result + ( ( methodName == null ) ? 0 : methodName.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
Invocation other = (Invocation) obj;
|
||||
if ( arguments == null ) {
|
||||
if ( other.arguments != null ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( !arguments.equals( other.arguments ) ) {
|
||||
return false;
|
||||
}
|
||||
if ( methodName == null ) {
|
||||
return other.methodName == null;
|
||||
}
|
||||
else {
|
||||
return methodName.equals( other.methodName );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
import org.mapstruct.Qualifier;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
@Qualifier
|
||||
public @interface Qualified {
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@AutoMapper(target = Target.class, uses = {ClassContainingCallbacks.class, BaseMapper.class})
|
||||
public class Source {
|
||||
private String foo;
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((foo == null) ? 0 : foo.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Source other = (Source) obj;
|
||||
if (foo == null) {
|
||||
return other.foo == null;
|
||||
} else {
|
||||
return foo.equals(other.foo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Source [foo=" + foo + "]";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public enum SourceEnum {
|
||||
A, B, C;
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
public class Target {
|
||||
private String foo;
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( ( foo == null ) ? 0 : foo.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
Target other = (Target) obj;
|
||||
if ( foo == null ) {
|
||||
return other.foo == null;
|
||||
}
|
||||
else {
|
||||
return foo.equals( other.foo );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Target [foo=" + foo + "]";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public enum TargetEnum {
|
||||
A, B, C;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMapper(target = AddressDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class)
|
||||
public class Address {
|
||||
|
||||
private String addressLine;
|
||||
private String town;
|
||||
|
||||
public String getAddressLine() {
|
||||
return addressLine;
|
||||
}
|
||||
|
||||
public void setAddressLine(String addressLine) {
|
||||
this.addressLine = addressLine;
|
||||
}
|
||||
|
||||
public String getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
public void setTown(String town) {
|
||||
this.town = town;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class AddressDto {
|
||||
|
||||
private int houseNumber;
|
||||
private String street;
|
||||
private String town;
|
||||
|
||||
public int getHouseNumber() {
|
||||
return houseNumber;
|
||||
}
|
||||
|
||||
public void setHouseNumber( int houseNumber ) {
|
||||
this.houseNumber = houseNumber;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet( String street ) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getTown() {
|
||||
return town;
|
||||
}
|
||||
|
||||
public void setTown( String town ) {
|
||||
this.town = town;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import java.util.List;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMapper(target = CompanyDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class)
|
||||
public class Company {
|
||||
|
||||
private List<Employee> employees;
|
||||
|
||||
public List<Employee> getEmployees() {
|
||||
return employees;
|
||||
}
|
||||
|
||||
public void setEmployees(List<Employee> employees) {
|
||||
this.employees = employees;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class CompanyDto {
|
||||
|
||||
private List<EmployeeDto> employees;
|
||||
|
||||
public List<EmployeeDto> getEmployees() {
|
||||
return employees;
|
||||
}
|
||||
|
||||
public void setEmployees( List<EmployeeDto> employees ) {
|
||||
this.employees = employees;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Component
|
||||
public class CompanyMapperPostProcessing {
|
||||
|
||||
@AfterMapping
|
||||
public void toAddressDto(Address address, @MappingTarget AddressDto addressDto) {
|
||||
String addressLine = address.getAddressLine();
|
||||
int separatorIndex = addressLine.indexOf( ";" );
|
||||
addressDto.setStreet( addressLine.substring( 0, separatorIndex ) );
|
||||
String houseNumber = addressLine.substring( separatorIndex + 1 );
|
||||
addressDto.setHouseNumber( Integer.parseInt( houseNumber ) );
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMapper(target = EmployeeDto.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, uses = CompanyMapperPostProcessing.class, mapperNameSuffix = "$1")
|
||||
public class Employee {
|
||||
|
||||
private Address address;
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.callbacks.ongeneratedmethods;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class EmployeeDto {
|
||||
|
||||
private AddressDto address;
|
||||
|
||||
public AddressDto getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress( AddressDto address ) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = CarEntity.class, uses = CarMapper.class)
|
||||
public class CarDto extends Identifiable {
|
||||
private int seatCount;
|
||||
|
||||
public int getSeatCount() {
|
||||
return seatCount;
|
||||
}
|
||||
|
||||
public void setSeatCount(int seatCount) {
|
||||
this.seatCount = seatCount;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
public class CarEntity extends Identifiable {
|
||||
private int seatCount;
|
||||
|
||||
public int getSeatCount() {
|
||||
return seatCount;
|
||||
}
|
||||
|
||||
public void setSeatCount(int seatCount) {
|
||||
this.seatCount = seatCount;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.BeforeMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*/
|
||||
@Component
|
||||
public class CarMapper {
|
||||
|
||||
@AfterMapping
|
||||
protected void neverMatched(ElectricCarDto electricDto) {
|
||||
throw new RuntimeException("must not be called");
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
protected void neverMatched(@MappingTarget ElectricCarEntity electricEntity) {
|
||||
throw new RuntimeException("must not be called");
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
protected void isCalled(@MappingTarget Object any) {
|
||||
if (any instanceof CarEntity) {
|
||||
CarEntity car = (CarEntity) any;
|
||||
if (car.getSeatCount() == 0) {
|
||||
car.setSeatCount(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
protected void incrementsTargetId(@MappingTarget Identifiable identifiable) {
|
||||
identifiable.setId(identifiable.getId() + 1);
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
protected void incrementsSourceId(Identifiable identifiable) {
|
||||
identifiable.setId(identifiable.getId() + 1);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
public class ElectricCarDto extends CarDto {
|
||||
private long batteryCapacity;
|
||||
|
||||
public long getBatteryCapacity() {
|
||||
return batteryCapacity;
|
||||
}
|
||||
|
||||
public void setBatteryCapacity(long batteryCapacity) {
|
||||
this.batteryCapacity = batteryCapacity;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
public class ElectricCarEntity extends Identifiable {
|
||||
private long batteryCapacity;
|
||||
|
||||
public long getBatteryCapacity() {
|
||||
return batteryCapacity;
|
||||
}
|
||||
|
||||
public void setBatteryCapacity(long batteryCapacity) {
|
||||
this.batteryCapacity = batteryCapacity;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package io.github.linpeilie.me.callbacks.typematching;
|
||||
|
||||
public abstract class Identifiable {
|
||||
private long id;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
public enum Colour {
|
||||
RED, GREEN, BLUE;
|
||||
}
|
||||
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@AutoMapper(target = Target.class, uses = SourceTargetMapper.class)
|
||||
public class Source {
|
||||
|
||||
private List<String> publicStringList;
|
||||
|
||||
private List<String> stringList;
|
||||
private List<String> otherStringList;
|
||||
private ArrayList<String> stringArrayList;
|
||||
|
||||
private Set<String> stringSet;
|
||||
private HashSet<String> stringHashSet;
|
||||
|
||||
private Collection<String> stringCollection;
|
||||
|
||||
@AutoMapping(target = "integerCollection")
|
||||
private List<Integer> integerList;
|
||||
|
||||
@AutoMapping(target = "set")
|
||||
private Set<Integer> integerSet;
|
||||
|
||||
@AutoMapping(target = "anotherStringSet")
|
||||
private Set<Integer> anotherIntegerSet;
|
||||
|
||||
private Set<Colour> colours;
|
||||
|
||||
private Map<String, Long> stringLongMap;
|
||||
|
||||
private Map<String, Long> otherStringLongMap;
|
||||
|
||||
@AutoMapping(target = "nonGenericMapStringtoLong")
|
||||
private Map<String, Long> stringLongMapForNonGeneric;
|
||||
|
||||
@AutoMapping(target = "stringListNoSetter")
|
||||
private List<String> stringList2;
|
||||
|
||||
@AutoMapping(target = "stringListNoSetter2")
|
||||
private Set<String> stringSet2;
|
||||
|
||||
private EnumSet<Colour> enumSet;
|
||||
|
||||
@AutoMapping(target = "nonGenericStringList")
|
||||
private List<String> stringList3;
|
||||
|
||||
public List<String> getPublicStringList() {
|
||||
return publicStringList;
|
||||
}
|
||||
|
||||
public void setPublicStringList(List<String> publicStringList) {
|
||||
this.publicStringList = publicStringList;
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return stringList;
|
||||
}
|
||||
|
||||
public void setStringList(List<String> stringList) {
|
||||
this.stringList = stringList;
|
||||
}
|
||||
|
||||
public ArrayList<String> getStringArrayList() {
|
||||
return stringArrayList;
|
||||
}
|
||||
|
||||
public void setStringArrayList(ArrayList<String> stringArrayList) {
|
||||
this.stringArrayList = stringArrayList;
|
||||
}
|
||||
|
||||
public Set<String> getStringSet() {
|
||||
return stringSet;
|
||||
}
|
||||
|
||||
public void setStringSet(Set<String> stringSet) {
|
||||
this.stringSet = stringSet;
|
||||
}
|
||||
|
||||
public HashSet<String> getStringHashSet() {
|
||||
return stringHashSet;
|
||||
}
|
||||
|
||||
public void setStringHashSet(HashSet<String> stringHashSet) {
|
||||
this.stringHashSet = stringHashSet;
|
||||
}
|
||||
|
||||
public Collection<String> getStringCollection() {
|
||||
return stringCollection;
|
||||
}
|
||||
|
||||
public void setStringCollection(Collection<String> stringCollection) {
|
||||
this.stringCollection = stringCollection;
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerList() {
|
||||
return integerList;
|
||||
}
|
||||
|
||||
public void setIntegerList(List<Integer> integerList) {
|
||||
this.integerList = integerList;
|
||||
}
|
||||
|
||||
public Set<Integer> getIntegerSet() {
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public void setIntegerSet(Set<Integer> integerSet) {
|
||||
this.integerSet = integerSet;
|
||||
}
|
||||
|
||||
public Set<Integer> getAnotherIntegerSet() {
|
||||
return anotherIntegerSet;
|
||||
}
|
||||
|
||||
public void setAnotherIntegerSet(Set<Integer> anotherIntegerSet) {
|
||||
this.anotherIntegerSet = anotherIntegerSet;
|
||||
}
|
||||
|
||||
public Set<Colour> getColours() {
|
||||
return colours;
|
||||
}
|
||||
|
||||
public void setColours(Set<Colour> colours) {
|
||||
this.colours = colours;
|
||||
}
|
||||
|
||||
public Map<String, Long> getStringLongMap() {
|
||||
return stringLongMap;
|
||||
}
|
||||
|
||||
public void setStringLongMap(Map<String, Long> stringLongMap) {
|
||||
this.stringLongMap = stringLongMap;
|
||||
}
|
||||
|
||||
public List<String> getStringList2() {
|
||||
return stringList2;
|
||||
}
|
||||
|
||||
public void setStringList2(List<String> stringList2) {
|
||||
this.stringList2 = stringList2;
|
||||
}
|
||||
|
||||
public List<String> getOtherStringList() {
|
||||
return otherStringList;
|
||||
}
|
||||
|
||||
public void setOtherStringList(List<String> otherStringList) {
|
||||
this.otherStringList = otherStringList;
|
||||
}
|
||||
|
||||
public Map<String, Long> getOtherStringLongMap() {
|
||||
return otherStringLongMap;
|
||||
}
|
||||
|
||||
public void setOtherStringLongMap(Map<String, Long> otherStringLongMap) {
|
||||
this.otherStringLongMap = otherStringLongMap;
|
||||
}
|
||||
|
||||
public Set<String> getStringSet2() {
|
||||
return stringSet2;
|
||||
}
|
||||
|
||||
public void setStringSet2(Set<String> stringSet2) {
|
||||
this.stringSet2 = stringSet2;
|
||||
}
|
||||
|
||||
public EnumSet<Colour> getEnumSet() {
|
||||
return enumSet;
|
||||
}
|
||||
|
||||
public void setEnumSet(EnumSet<Colour> enumSet) {
|
||||
this.enumSet = enumSet;
|
||||
}
|
||||
|
||||
public List<String> getStringList3() {
|
||||
return stringList3;
|
||||
}
|
||||
|
||||
public void setStringList3(List<String> stringList3) {
|
||||
this.stringList3 = stringList3;
|
||||
}
|
||||
|
||||
public Map<String, Long> getStringLongMapForNonGeneric() {
|
||||
return stringLongMapForNonGeneric;
|
||||
}
|
||||
|
||||
public void setStringLongMapForNonGeneric(Map<String, Long> stringLongMapForNonGeneric) {
|
||||
this.stringLongMapForNonGeneric = stringLongMapForNonGeneric;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SourceTargetMapper {
|
||||
|
||||
protected StringHolder toStringHolder(String string) {
|
||||
return new StringHolder( string );
|
||||
}
|
||||
|
||||
protected String toString(StringHolder string) {
|
||||
return string.getString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class StringHolder {
|
||||
private final String string;
|
||||
|
||||
public StringHolder(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( ( string == null ) ? 0 : string.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
StringHolder other = (StringHolder) obj;
|
||||
if ( string == null ) {
|
||||
return other.string == null;
|
||||
}
|
||||
else {
|
||||
return string.equals( other.string );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Stefan May
|
||||
*/
|
||||
public class StringHolderArrayList extends ArrayList<StringHolder> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Stefan May
|
||||
*/
|
||||
public class StringHolderToLongMap extends HashMap<StringHolder, Long> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Target {
|
||||
|
||||
//CHECKSTYLE:OFF
|
||||
public List<String> publicStringList;
|
||||
//CHECKSTYLE:On
|
||||
|
||||
private List<String> stringList;
|
||||
private List<String> otherStringList;
|
||||
private ArrayList<String> stringArrayList;
|
||||
|
||||
private Set<String> stringSet;
|
||||
private HashSet<String> stringHashSet;
|
||||
|
||||
private Collection<String> stringCollection;
|
||||
|
||||
private Collection<Integer> integerCollection;
|
||||
|
||||
private Set<String> anotherStringSet;
|
||||
|
||||
private Set<String> colours;
|
||||
|
||||
private Map<String, Long> stringLongMap;
|
||||
private Map<String, Long> otherStringLongMap;
|
||||
|
||||
private List<String> stringListNoSetter;
|
||||
|
||||
private List<String> stringListNoSetter2;
|
||||
|
||||
@SuppressWarnings( "rawtypes" )
|
||||
private Set set;
|
||||
|
||||
private EnumSet<Colour> enumSet;
|
||||
|
||||
private StringHolderArrayList nonGenericStringList;
|
||||
|
||||
private StringHolderToLongMap nonGenericMapStringtoLong;
|
||||
|
||||
public Target() {
|
||||
otherStringLongMap = new HashMap<>();
|
||||
otherStringLongMap.put( "not-present-after-mapping", 42L );
|
||||
|
||||
otherStringList = new ArrayList<>();
|
||||
otherStringList.add( "not-present-after-mapping" );
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return stringList;
|
||||
}
|
||||
|
||||
public void setStringList(List<String> stringList) {
|
||||
this.stringList = stringList;
|
||||
}
|
||||
|
||||
public ArrayList<String> getStringArrayList() {
|
||||
return stringArrayList;
|
||||
}
|
||||
|
||||
public void setStringArrayList(ArrayList<String> stringArrayList) {
|
||||
this.stringArrayList = stringArrayList;
|
||||
}
|
||||
|
||||
public Set<String> getStringSet() {
|
||||
return stringSet;
|
||||
}
|
||||
|
||||
public void setStringSet(Set<String> stringSet) {
|
||||
this.stringSet = stringSet;
|
||||
}
|
||||
|
||||
public HashSet<String> getStringHashSet() {
|
||||
return stringHashSet;
|
||||
}
|
||||
|
||||
public void setStringHashSet(HashSet<String> stringHashSet) {
|
||||
this.stringHashSet = stringHashSet;
|
||||
}
|
||||
|
||||
public Collection<String> getStringCollection() {
|
||||
return stringCollection;
|
||||
}
|
||||
|
||||
public void setStringCollection(Collection<String> stringCollection) {
|
||||
this.stringCollection = stringCollection;
|
||||
}
|
||||
|
||||
public Collection<Integer> getIntegerCollection() {
|
||||
return integerCollection;
|
||||
}
|
||||
|
||||
public void setIntegerCollection(Collection<Integer> integerCollection) {
|
||||
this.integerCollection = integerCollection;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Set getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void setSet(Set set) {
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
public Set<String> getAnotherStringSet() {
|
||||
return anotherStringSet;
|
||||
}
|
||||
|
||||
public void setAnotherStringSet(Set<String> anotherStringSet) {
|
||||
this.anotherStringSet = anotherStringSet;
|
||||
}
|
||||
|
||||
public void setColours(Set<String> colours) {
|
||||
this.colours = colours;
|
||||
}
|
||||
|
||||
public Set<String> getColours() {
|
||||
return colours;
|
||||
}
|
||||
|
||||
public Map<String, Long> getStringLongMap() {
|
||||
return stringLongMap;
|
||||
}
|
||||
|
||||
public void setStringLongMap(Map<String, Long> stringLongMap) {
|
||||
this.stringLongMap = stringLongMap;
|
||||
}
|
||||
|
||||
public List<String> getStringListNoSetter() {
|
||||
if ( stringListNoSetter == null ) {
|
||||
stringListNoSetter = new ArrayList<>();
|
||||
}
|
||||
return stringListNoSetter;
|
||||
}
|
||||
|
||||
public List<String> getStringListNoSetter2() {
|
||||
if ( stringListNoSetter2 == null ) {
|
||||
stringListNoSetter2 = new ArrayList<>();
|
||||
}
|
||||
return stringListNoSetter2;
|
||||
}
|
||||
|
||||
public Map<String, Long> getOtherStringLongMap() {
|
||||
return otherStringLongMap;
|
||||
}
|
||||
|
||||
public void setOtherStringLongMap(Map<String, Long> otherStringLongMap) {
|
||||
this.otherStringLongMap = otherStringLongMap;
|
||||
}
|
||||
|
||||
public List<String> getOtherStringList() {
|
||||
return otherStringList;
|
||||
}
|
||||
|
||||
public void setOtherStringList(List<String> otherStringList) {
|
||||
this.otherStringList = otherStringList;
|
||||
}
|
||||
|
||||
public EnumSet<Colour> getEnumSet() {
|
||||
return enumSet;
|
||||
}
|
||||
|
||||
public void setEnumSet(EnumSet<Colour> enumSet) {
|
||||
this.enumSet = enumSet;
|
||||
}
|
||||
|
||||
public StringHolderArrayList getNonGenericStringList() {
|
||||
return nonGenericStringList;
|
||||
}
|
||||
|
||||
public void setNonGenericStringList(StringHolderArrayList nonGenericStringList) {
|
||||
this.nonGenericStringList = nonGenericStringList;
|
||||
}
|
||||
|
||||
public StringHolderToLongMap getNonGenericMapStringtoLong() {
|
||||
return nonGenericMapStringtoLong;
|
||||
}
|
||||
|
||||
public void setNonGenericMapStringtoLong(StringHolderToLongMap nonGenericMapStringtoLong) {
|
||||
this.nonGenericMapStringtoLong = nonGenericMapStringtoLong;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TestList<E> extends ArrayList<E> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static boolean addAllCalled = false;
|
||||
|
||||
public static boolean isAddAllCalled() {
|
||||
return addAllCalled;
|
||||
}
|
||||
|
||||
public static void setAddAllCalled(boolean addAllCalled) {
|
||||
TestList.addAllCalled = addAllCalled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
addAllCalled = true;
|
||||
return super.addAll( c );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TestMap<K, V> extends HashMap<K, V> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static boolean puttAllCalled = false;
|
||||
|
||||
public static boolean isPuttAllCalled() {
|
||||
return puttAllCalled;
|
||||
}
|
||||
|
||||
public static void setPuttAllCalled(boolean puttAllCalled) {
|
||||
TestMap.puttAllCalled = puttAllCalled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends K, ? extends V> m) {
|
||||
puttAllCalled = true;
|
||||
super.putAll( m );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class CatException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CatException() {
|
||||
}
|
||||
|
||||
public CatException(String msg) {
|
||||
super( msg );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class DogException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DogException() {
|
||||
}
|
||||
|
||||
public DogException(String msg) {
|
||||
super( msg );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.github.linpeilie.me.collection.adder._target.IndoorPet;
|
||||
import io.github.linpeilie.me.collection.adder._target.OutdoorPet;
|
||||
import io.github.linpeilie.me.collection.adder._target.Pet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.mapstruct.TargetType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Component
|
||||
public class PetMapper {
|
||||
|
||||
private static final Map<String, Long> PETS_TO_TARGET = ImmutableMap.<String, Long>builder()
|
||||
.put( "rabbit", 1L )
|
||||
.put( "mouse", 2L ).build();
|
||||
|
||||
private static final Map<Long, String> PETS_TO_SOURCE = ImmutableMap.<Long, String>builder()
|
||||
.put( 1L, "rabbit" )
|
||||
.put( 2L, "mouse" )
|
||||
.put( 3L, "cat" )
|
||||
.put( 4L, "dog" ).build();
|
||||
|
||||
/**
|
||||
* method to be used when using an adder
|
||||
*
|
||||
* @param pet
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws CatException
|
||||
* @throws DogException
|
||||
*/
|
||||
public Long toPet(String pet) throws CatException, DogException {
|
||||
if ( "cat".equals( pet ) ) {
|
||||
throw new CatException();
|
||||
}
|
||||
else if ( "dog".equals( pet ) ) {
|
||||
throw new DogException();
|
||||
}
|
||||
return PETS_TO_TARGET.get( pet );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to be used when not using an adder
|
||||
*
|
||||
* @param pets
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws CatException
|
||||
* @throws DogException
|
||||
*/
|
||||
public List<Long> toPets(List<String> pets) throws CatException, DogException {
|
||||
List<Long> result = new ArrayList<>();
|
||||
for ( String pet : pets ) {
|
||||
result.add( toPet( pet ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Pet> T toPet(String pet, @TargetType Class<T> clazz) throws CatException, DogException {
|
||||
if ( clazz == IndoorPet.class ) {
|
||||
return (T) new IndoorPet( toPet( pet ) );
|
||||
}
|
||||
if ( clazz == OutdoorPet.class ) {
|
||||
return (T) new OutdoorPet( toPet( pet ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> toSourcePets(List<Long> pets) throws CatException, DogException {
|
||||
List<String> result = new ArrayList<>();
|
||||
for ( Long pet : pets ) {
|
||||
result.add( PETS_TO_SOURCE.get( pet ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@Component
|
||||
public class TeethMapper {
|
||||
|
||||
private static final Map<String, Integer> TEETH = ImmutableMap.<String, Integer>builder()
|
||||
.put( "incisor", 1 )
|
||||
.put( "canine", 2 )
|
||||
.put( "moler", 3 ).build();
|
||||
|
||||
public Integer toTooth(String tooth) {
|
||||
return TEETH.get( tooth );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class AdderUsageObserver {
|
||||
|
||||
private AdderUsageObserver() {
|
||||
}
|
||||
|
||||
private static boolean used = false;
|
||||
|
||||
public static boolean isUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public static void setUsed(boolean used) {
|
||||
AdderUsageObserver.used = used;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class IndoorPet extends Pet {
|
||||
|
||||
private Long value;
|
||||
|
||||
public IndoorPet(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class OutdoorPet extends Pet {
|
||||
|
||||
private Long value;
|
||||
|
||||
public OutdoorPet(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Long getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Long value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Pet {
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Target {
|
||||
|
||||
private List<Long> pets;
|
||||
|
||||
public List<Long> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<Long> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
public void addCat(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addDog(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addPets(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public Long addPet(Long pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( pets == null ) {
|
||||
pets = new ArrayList<>();
|
||||
}
|
||||
pets.add( pet );
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import io.github.linpeilie.me.collection.adder.source.Foo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Target2 {
|
||||
|
||||
private List<Foo> attributes = new ArrayList<Foo>();
|
||||
|
||||
public Foo addAttribute( Foo foo ) {
|
||||
attributes.add( foo );
|
||||
return foo;
|
||||
}
|
||||
|
||||
public List<Foo> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes( List<Foo> attributes ) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Target3 {
|
||||
|
||||
private List<Long> pets;
|
||||
|
||||
public List<Long> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<Long> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
public void addCat(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addDog(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addPets(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public Long addPet(Long pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( pets == null ) {
|
||||
pets = new ArrayList<>();
|
||||
}
|
||||
pets.add( pet );
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TargetDali {
|
||||
|
||||
private List<Integer> teeth;
|
||||
|
||||
public List<Integer> getTeeth() {
|
||||
return teeth;
|
||||
}
|
||||
|
||||
public void setTeeth(List<Integer> teeth) {
|
||||
this.teeth = teeth;
|
||||
}
|
||||
|
||||
public void addTeeth(Integer tooth) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( teeth == null ) {
|
||||
teeth = new ArrayList<>();
|
||||
}
|
||||
teeth.add( tooth );
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TargetHuman {
|
||||
|
||||
private List<Integer> teeth;
|
||||
|
||||
public List<Integer> getTeeth() {
|
||||
return teeth;
|
||||
}
|
||||
|
||||
public void setTeeth(List<Integer> teeth) {
|
||||
this.teeth = teeth;
|
||||
}
|
||||
|
||||
public void addTooth(Integer pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( teeth == null ) {
|
||||
teeth = new ArrayList<>();
|
||||
}
|
||||
teeth.add( pet );
|
||||
}
|
||||
|
||||
public void addTeeth(Integer tooth) {
|
||||
if ( teeth == null ) {
|
||||
teeth = new ArrayList<>();
|
||||
}
|
||||
teeth.add( tooth );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TargetOnlyGetter {
|
||||
|
||||
private List<Long> pets;
|
||||
|
||||
public List<Long> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void addCat(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addDog(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addPets(Long cat) {
|
||||
// dummy method to test selection mechanism
|
||||
}
|
||||
|
||||
public void addPet(Long pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( pets == null ) {
|
||||
pets = new ArrayList<>();
|
||||
}
|
||||
pets.add( pet );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TargetViaTargetType {
|
||||
|
||||
private List<IndoorPet> pets;
|
||||
|
||||
public List<IndoorPet> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<IndoorPet> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
public void addPet(IndoorPet pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( pets == null ) {
|
||||
pets = new ArrayList<>();
|
||||
}
|
||||
pets.add( pet );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class TargetWithAnimals {
|
||||
|
||||
private List<String> animals = new ArrayList<>();
|
||||
|
||||
public List<String> getAnimals() {
|
||||
return animals;
|
||||
}
|
||||
|
||||
public void setAnimals(List<String> animals) {
|
||||
this.animals = animals;
|
||||
}
|
||||
|
||||
public void addAnimal(String animal) {
|
||||
animals.add( animal );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder._target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class TargetWithoutSetter {
|
||||
|
||||
private List<Long> pets;
|
||||
|
||||
public List<Long> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void addPet(Long pet) {
|
||||
AdderUsageObserver.setUsed( true );
|
||||
if ( pets == null ) {
|
||||
pets = new ArrayList<>();
|
||||
}
|
||||
pets.add( pet );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Foo {
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.me.collection.adder.PetMapper;
|
||||
import io.github.linpeilie.me.collection.adder.TeethMapper;
|
||||
import io.github.linpeilie.me.collection.adder._target.Target;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMapper(target = Target.class, reverseConvertGenerate = false, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
|
||||
PetMapper.class, TeethMapper.class})
|
||||
public class SingleElementSource {
|
||||
|
||||
@AutoMapping(target = "pets")
|
||||
private String pet;
|
||||
|
||||
public String getPet() {
|
||||
return pet;
|
||||
}
|
||||
|
||||
public void setPet(String pet) {
|
||||
this.pet = pet;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import io.github.linpeilie.me.collection.adder.PetMapper;
|
||||
import io.github.linpeilie.me.collection.adder.TeethMapper;
|
||||
import io.github.linpeilie.me.collection.adder._target.Target;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetOnlyGetter;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetViaTargetType;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetWithoutSetter;
|
||||
import java.util.List;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = Target.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
|
||||
PetMapper.class, TeethMapper.class}),
|
||||
@AutoMapper(target = TargetOnlyGetter.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
|
||||
PetMapper.class, TeethMapper.class}),
|
||||
@AutoMapper(target = TargetViaTargetType.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, uses = {
|
||||
PetMapper.class, TeethMapper.class}, reverseConvertGenerate = false),
|
||||
@AutoMapper(target = TargetWithoutSetter.class,
|
||||
collectionMappingStrategy = CollectionMappingStrategy.SETTER_PREFERRED,
|
||||
uses = {PetMapper.class}
|
||||
)
|
||||
})
|
||||
public class Source {
|
||||
|
||||
private List<String> pets;
|
||||
|
||||
public List<String> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<String> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.me.collection.adder._target.Target2;
|
||||
import java.util.List;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMapper(target = Target2.class,
|
||||
reverseConvertGenerate = false,
|
||||
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
|
||||
public class Source2 {
|
||||
|
||||
private List<Foo> attributes;
|
||||
|
||||
public List<Foo> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(List<Foo> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.me.collection.adder.PetMapper;
|
||||
import io.github.linpeilie.me.collection.adder._target.Target3;
|
||||
import java.util.List;
|
||||
|
||||
@AutoMapper(target = Target3.class, uses = PetMapper.class)
|
||||
public class Source3 {
|
||||
|
||||
private List<String> pets;
|
||||
|
||||
public List<String> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<String> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import io.github.linpeilie.me.collection.adder.PetMapper;
|
||||
import io.github.linpeilie.me.collection.adder.TeethMapper;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetDali;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetHuman;
|
||||
import java.util.List;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = TargetDali.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
|
||||
uses = {PetMapper.class, TeethMapper.class}),
|
||||
@AutoMapper(target = TargetHuman.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
|
||||
uses = {PetMapper.class, TeethMapper.class})
|
||||
})
|
||||
public class SourceTeeth {
|
||||
|
||||
private List<String> teeth;
|
||||
|
||||
public List<String> getTeeth() {
|
||||
return teeth;
|
||||
}
|
||||
|
||||
public void setTeeth(List<String> teeth) {
|
||||
this.teeth = teeth;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
package io.github.linpeilie.me.collection.adder.source;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import io.github.linpeilie.me.collection.adder._target.TargetWithAnimals;
|
||||
import java.util.List;
|
||||
import org.mapstruct.CollectionMappingStrategy;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
/**
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@AutoMapper(target = TargetWithAnimals.class, collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
|
||||
public class SourceWithPets {
|
||||
|
||||
@AutoMapping(target = "animals")
|
||||
private List<String> pets;
|
||||
|
||||
public List<String> getPets() {
|
||||
return pets;
|
||||
}
|
||||
|
||||
public void setPets(List<String> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = NoSetterTarget.class)
|
||||
})
|
||||
public class NoSetterSource {
|
||||
private List<String> listValues;
|
||||
private Map<String, String> mapValues;
|
||||
|
||||
public List<String> getListValues() {
|
||||
return listValues;
|
||||
}
|
||||
|
||||
public void setListValues(List<String> listValues) {
|
||||
this.listValues = listValues;
|
||||
}
|
||||
|
||||
public Map<String, String> getMapValues() {
|
||||
return mapValues;
|
||||
}
|
||||
|
||||
public void setMapValues(Map<String, String> mapValues) {
|
||||
this.mapValues = mapValues;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Andreas Gudian
|
||||
*
|
||||
*/
|
||||
public class NoSetterTarget {
|
||||
private List<String> listValues = new ArrayList<String>();
|
||||
private Map<String, String> mapValues = new HashMap<String, String>();
|
||||
|
||||
public List<String> getListValues() {
|
||||
return listValues;
|
||||
}
|
||||
|
||||
public Map<String, String> getMapValues() {
|
||||
return mapValues;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.github.linpeilie.annotations.AutoMappers;
|
||||
import io.github.linpeilie.annotations.AutoMapping;
|
||||
import java.util.List;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@AutoMappers({
|
||||
@AutoMapper(target = Target.class)
|
||||
})
|
||||
public class Source {
|
||||
|
||||
@AutoMapping(target = "fooListNoSetter")
|
||||
private List<SourceFoo> fooList;
|
||||
|
||||
public List<SourceFoo> getFooList() {
|
||||
return fooList;
|
||||
}
|
||||
|
||||
public void setFooList(List<SourceFoo> fooList) {
|
||||
this.fooList = fooList;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
|
||||
@AutoMapper(target = TargetFoo.class)
|
||||
public class SourceFoo {
|
||||
|
||||
private String name;
|
||||
|
||||
public SourceFoo() {
|
||||
}
|
||||
|
||||
public SourceFoo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Target {
|
||||
|
||||
private List<TargetFoo> fooListNoSetter;
|
||||
|
||||
public List<TargetFoo> getFooListNoSetter() {
|
||||
if ( fooListNoSetter == null ) {
|
||||
fooListNoSetter = new ArrayList<>();
|
||||
}
|
||||
return fooListNoSetter;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.defaultimplementation;
|
||||
|
||||
public class TargetFoo implements Comparable<TargetFoo> {
|
||||
|
||||
private String name;
|
||||
|
||||
public TargetFoo() {
|
||||
}
|
||||
|
||||
public TargetFoo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ( ( name == null ) ? 0 : name.hashCode() );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ( this == obj ) {
|
||||
return true;
|
||||
}
|
||||
if ( obj == null ) {
|
||||
return false;
|
||||
}
|
||||
if ( getClass() != obj.getClass() ) {
|
||||
return false;
|
||||
}
|
||||
TargetFoo other = (TargetFoo) obj;
|
||||
if ( name == null ) {
|
||||
return other.name == null;
|
||||
}
|
||||
else {
|
||||
return name.equals( other.name );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TargetFoo o) {
|
||||
return getName().compareTo( o.getName() );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright MapStruct Authors.
|
||||
*
|
||||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package io.github.linpeilie.me.collection.forged;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Bar {
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user