├── .assets
├── documentation.png
├── logo.png
└── mapping.png
├── .editorconfig
├── .github
└── workflows
│ ├── publish.yml
│ ├── release.yml
│ └── test.yml
├── .gitignore
├── .idea
└── copyright
│ ├── ShapeShift.xml
│ └── profiles_settings.xml
├── .releaserc.json
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.gradle.kts
├── buildSrc
├── build.gradle.kts
└── src
│ └── main
│ └── kotlin
│ └── dev.krud.shapeshift.common-conventions.gradle.kts
├── docs
└── getting_started.md
├── example
├── java
│ ├── buildSrc
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── dev.krud.shapeshift.examples.java.common-conventions.gradle.kts
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ ├── simple-mapping
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ └── java
│ │ │ │ └── dev
│ │ │ │ └── krud
│ │ │ │ └── shapeshift
│ │ │ │ └── examples
│ │ │ │ └── java
│ │ │ │ ├── SimpleEntity.java
│ │ │ │ └── SimpleEntityDisplay.java
│ │ │ └── test
│ │ │ └── java
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── java
│ │ │ └── SimpleMappingTests.java
│ ├── spring-mapping
│ │ ├── build.gradle.kts
│ │ └── src
│ │ │ ├── main
│ │ │ └── java
│ │ │ │ └── dev
│ │ │ │ └── krud
│ │ │ │ └── shapeshift
│ │ │ │ └── examples
│ │ │ │ └── java
│ │ │ │ ├── BeanTransformer.java
│ │ │ │ ├── SimpleEntity.java
│ │ │ │ ├── SimpleEntityDisplay.java
│ │ │ │ └── SpringMappingApplication.java
│ │ │ └── test
│ │ │ └── java
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── java
│ │ │ └── SpringMappingTests.java
│ └── transformer-mapping
│ │ ├── build.gradle.kts
│ │ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── java
│ │ │ ├── SimpleEntity.java
│ │ │ ├── SimpleEntityDisplay.java
│ │ │ └── StringToCommaSeparatedStringListTransformer.java
│ │ └── test
│ │ └── java
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── java
│ │ └── TransformerMappingTests.java
└── kotlin
│ ├── advanced-mapping
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── kotlin
│ │ │ ├── AdvancedChildEntity.kt
│ │ │ ├── AdvancedEntity.kt
│ │ │ ├── AdvancedEntityDisplay.kt
│ │ │ ├── Main.kt
│ │ │ └── ReducedAdvancedEntityDisplay.kt
│ │ └── test
│ │ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── kotlin
│ │ └── AdvancedMappingTests.kt
│ ├── buildSrc
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── dev.krud.shapeshift.examples.kotlin.common-conventions.gradle.kts
│ ├── dsl-mapping
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── kotlin
│ │ │ ├── Main.kt
│ │ │ ├── SimpleEntity.kt
│ │ │ └── SimpleEntityDisplay.kt
│ │ └── test
│ │ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── kotlin
│ │ └── SimpleMappingTests.kt
│ ├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle.kts
│ ├── simple-mapping
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── dev
│ │ │ └── krud
│ │ │ └── shapeshift
│ │ │ └── examples
│ │ │ └── kotlin
│ │ │ ├── Main.kt
│ │ │ ├── SimpleEntity.kt
│ │ │ └── SimpleEntityDisplay.kt
│ │ └── test
│ │ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── kotlin
│ │ └── SimpleMappingTests.kt
│ ├── spring-mapping
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── kotlin
│ │ ├── BeanTransformer.kt
│ │ ├── Main.kt
│ │ ├── SimpleEntity.kt
│ │ └── SimpleEntityDisplay.kt
│ └── transformer-mapping
│ ├── build.gradle.kts
│ └── src
│ ├── main
│ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── examples
│ │ └── kotlin
│ │ ├── Main.kt
│ │ ├── SimpleEntity.kt
│ │ ├── SimpleEntityDisplay.kt
│ │ └── StringToCommaSeparatedStringListTransformer.kt
│ └── test
│ └── kotlin
│ └── dev
│ └── krud
│ └── shapeshift
│ └── examples
│ └── kotlin
│ └── TransformerMappingTests.kt
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── ops
└── release.sh
├── settings.gradle.kts
├── shapeshift
├── build.gradle.kts
└── src
│ ├── main
│ └── kotlin
│ │ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ ├── MappingDecoratorRegistration.kt
│ │ ├── MappingStrategy.kt
│ │ ├── MappingTransformerRegistration.kt
│ │ ├── ShapeShift.kt
│ │ ├── ShapeShiftBuilder.kt
│ │ ├── builder
│ │ └── MappingDefinitionBuilder.kt
│ │ ├── condition
│ │ ├── MappingCondition.kt
│ │ └── MappingConditionContext.kt
│ │ ├── container
│ │ ├── ContainerAdapter.kt
│ │ └── OptionalContainerAdapter.kt
│ │ ├── decorator
│ │ ├── EmptyDecorator.kt
│ │ ├── MappingDecorator.kt
│ │ └── MappingDecoratorContext.kt
│ │ ├── dsl
│ │ ├── KotlinDslMappingDefinitionBuilder.kt
│ │ └── KotlinMappingDsl.kt
│ │ ├── dto
│ │ ├── MappingStructure.kt
│ │ ├── ObjectFieldTrio.kt
│ │ ├── ResolvedMappedField.kt
│ │ └── TransformerCoordinates.kt
│ │ ├── enums
│ │ └── AutoMappingStrategy.kt
│ │ ├── resolver
│ │ ├── MappingDefinition.kt
│ │ ├── MappingDefinitionResolver.kt
│ │ ├── StaticMappingDefinitionResolver.kt
│ │ └── annotation
│ │ │ ├── AnnotationMappingDefinitionResolver.kt
│ │ │ ├── AutoMapping.kt
│ │ │ ├── DefaultMappingTarget.kt
│ │ │ └── MappedField.kt
│ │ ├── transformer
│ │ ├── AnyToStringMappingTransformer.kt
│ │ ├── DateToLongMappingTransformer.kt
│ │ ├── EmptyTransformer.kt
│ │ ├── ImplicitCollectionMappingTransformer.kt
│ │ ├── ImplicitMappingTransformer.kt
│ │ ├── LongToDateMappingTransformer.kt
│ │ ├── NumberToCharMappingTransformer.kt
│ │ ├── NumberToDoubleMappingTransformer.kt
│ │ ├── NumberToFloatMappingTransformer.kt
│ │ ├── NumberToIntMappingTransformer.kt
│ │ ├── NumberToLongMappingTransformer.kt
│ │ ├── NumberToShortMappingTransformer.kt
│ │ ├── StringToBooleanMappingTransformer.kt
│ │ ├── StringToCharMappingTransformer.kt
│ │ ├── StringToDoubleMappingTransformer.kt
│ │ ├── StringToFloatMappingTransformer.kt
│ │ ├── StringToIntMappingTransformer.kt
│ │ ├── StringToLongMappingTransformer.kt
│ │ ├── StringToShortMappingTransformer.kt
│ │ └── base
│ │ │ ├── MappingTransformer.kt
│ │ │ └── MappingTransformerContext.kt
│ │ └── util
│ │ ├── AutoMappingUtil.kt
│ │ ├── MapUtils.kt
│ │ ├── ReflectionUtils.kt
│ │ └── StringUtils.kt
│ └── test
│ └── kotlin
│ └── dev
│ └── krud
│ └── shapeshift
│ ├── ShapeShiftBuilderTests.kt
│ ├── ShapeShiftTests.kt
│ ├── ValueContainerTest.kt
│ ├── _fixtures.kt
│ ├── builder
│ └── MappingDefinitionBuilderTests.kt
│ ├── dsl
│ └── KotlinDslMappingDefinitionBuilderTests.kt
│ └── transformer
│ ├── ShapeShiftTransformerTests.kt
│ └── _fixtures.kt
└── spring-boot-starter-shapeshift
├── build.gradle.kts
└── src
├── main
├── kotlin
│ └── dev
│ │ └── krud
│ │ └── shapeshift
│ │ └── spring
│ │ ├── ShapeShiftAutoConfiguration.kt
│ │ ├── ShapeShiftBuilderCustomizer.kt
│ │ └── customizer
│ │ ├── ShapeShiftDecoratorCustomizer.kt
│ │ └── ShapeShiftTransformerCustomizer.kt
└── resources
│ └── META-INF
│ └── spring.factories
└── test
└── kotlin
└── dev
└── krud
└── shapeshift
└── spring
├── ShapeShiftSpringTest.kt
├── TestConfiguration.kt
└── _fixtures.kt
/.assets/documentation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/.assets/documentation.png
--------------------------------------------------------------------------------
/.assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/.assets/logo.png
--------------------------------------------------------------------------------
/.assets/mapping.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/.assets/mapping.png
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_size = 4
7 | indent_style = space
8 | insert_final_newline = false
9 | max_line_length = 240
10 | tab_width = 4
11 | ij_continuation_indent_size = 8
12 | ij_formatter_off_tag = @formatter:off
13 | ij_formatter_on_tag = @formatter:on
14 | ij_formatter_tags_enabled = false
15 | ij_smart_tabs = false
16 | ij_visual_guides = none
17 | ij_wrap_on_typing = false
18 |
19 | [{*.yaml,*.yml}]
20 | tab_width = 2
21 | indent_size = 2
22 |
23 | [{*.gradle.kts,*.kt,*.kts,*.main.kts,*.space.kts}]
24 | disabled_rules=filename
25 | ij_kotlin_align_in_columns_case_branch = false
26 | ij_kotlin_align_multiline_binary_operation = false
27 | ij_kotlin_align_multiline_extends_list = false
28 | ij_kotlin_align_multiline_method_parentheses = false
29 | ij_kotlin_align_multiline_parameters = true
30 | ij_kotlin_align_multiline_parameters_in_calls = false
31 | ij_kotlin_allow_trailing_comma = false
32 | ij_kotlin_allow_trailing_comma_on_call_site = false
33 | ij_kotlin_assignment_wrap = normal
34 | ij_kotlin_blank_lines_after_class_header = 0
35 | ij_kotlin_blank_lines_around_block_when_branches = 0
36 | ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
37 | ij_kotlin_block_comment_add_space = false
38 | ij_kotlin_block_comment_at_first_column = true
39 | ij_kotlin_call_parameters_new_line_after_left_paren = true
40 | ij_kotlin_call_parameters_right_paren_on_new_line = true
41 | ij_kotlin_call_parameters_wrap = on_every_item
42 | ij_kotlin_catch_on_new_line = false
43 | ij_kotlin_class_annotation_wrap = split_into_lines
44 | ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
45 | ij_kotlin_continuation_indent_for_chained_calls = false
46 | ij_kotlin_continuation_indent_for_expression_bodies = false
47 | ij_kotlin_continuation_indent_in_argument_lists = false
48 | ij_kotlin_continuation_indent_in_elvis = false
49 | ij_kotlin_continuation_indent_in_if_conditions = false
50 | ij_kotlin_continuation_indent_in_parameter_lists = false
51 | ij_kotlin_continuation_indent_in_supertype_lists = false
52 | ij_kotlin_else_on_new_line = false
53 | ij_kotlin_enum_constants_wrap = off
54 | ij_kotlin_extends_list_wrap = normal
55 | ij_kotlin_field_annotation_wrap = split_into_lines
56 | ij_kotlin_finally_on_new_line = false
57 | ij_kotlin_if_rparen_on_new_line = true
58 | ij_kotlin_import_nested_classes = false
59 | ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
60 | ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
61 | ij_kotlin_keep_blank_lines_before_right_brace = 2
62 | ij_kotlin_keep_blank_lines_in_code = 2
63 | ij_kotlin_keep_blank_lines_in_declarations = 2
64 | ij_kotlin_keep_first_column_comment = true
65 | ij_kotlin_keep_indents_on_empty_lines = false
66 | ij_kotlin_keep_line_breaks = true
67 | ij_kotlin_lbrace_on_next_line = false
68 | ij_kotlin_line_comment_add_space = false
69 | ij_kotlin_line_comment_add_space_on_reformat = false
70 | ij_kotlin_line_comment_at_first_column = true
71 | ij_kotlin_method_annotation_wrap = split_into_lines
72 | ij_kotlin_method_call_chain_wrap = normal
73 | ij_kotlin_method_parameters_new_line_after_left_paren = true
74 | ij_kotlin_method_parameters_right_paren_on_new_line = true
75 | ij_kotlin_method_parameters_wrap = on_every_item
76 | ij_kotlin_name_count_to_use_star_import = 2147483647
77 | ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
78 | ij_kotlin_packages_to_use_import_on_demand = java.util.*,kotlinx.android.synthetic.**,io.ktor.**
79 | ij_kotlin_parameter_annotation_wrap = off
80 | ij_kotlin_space_after_comma = true
81 | ij_kotlin_space_after_extend_colon = true
82 | ij_kotlin_space_after_type_colon = true
83 | ij_kotlin_space_before_catch_parentheses = true
84 | ij_kotlin_space_before_comma = false
85 | ij_kotlin_space_before_extend_colon = true
86 | ij_kotlin_space_before_for_parentheses = true
87 | ij_kotlin_space_before_if_parentheses = true
88 | ij_kotlin_space_before_lambda_arrow = true
89 | ij_kotlin_space_before_type_colon = false
90 | ij_kotlin_space_before_when_parentheses = true
91 | ij_kotlin_space_before_while_parentheses = true
92 | ij_kotlin_spaces_around_additive_operators = true
93 | ij_kotlin_spaces_around_assignment_operators = true
94 | ij_kotlin_spaces_around_equality_operators = true
95 | ij_kotlin_spaces_around_function_type_arrow = true
96 | ij_kotlin_spaces_around_logical_operators = true
97 | ij_kotlin_spaces_around_multiplicative_operators = true
98 | ij_kotlin_spaces_around_range = false
99 | ij_kotlin_spaces_around_relational_operators = true
100 | ij_kotlin_spaces_around_unary_operator = false
101 | ij_kotlin_spaces_around_when_arrow = true
102 | ij_kotlin_variable_annotation_wrap = off
103 | ij_kotlin_while_on_new_line = false
104 | ij_kotlin_wrap_elvis_expressions = 1
105 | ij_kotlin_wrap_expression_body_functions = 1
106 | ij_kotlin_wrap_first_method_in_call_chain = false
107 | ij_any_if_brace_force = always
108 | ij_any_for_brace_force = always
109 | ij_any_while_brace_force = always
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | tags:
8 | - v*
9 | pull_request:
10 | branches:
11 | - master
12 | jobs:
13 | publish:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Check out Git repository
17 | uses: actions/checkout@v3
18 | - name: Install Java
19 | uses: actions/setup-java@v3
20 | with:
21 | distribution: 'zulu'
22 | java-version: '17'
23 | - name: Cache Gradle packages
24 | uses: actions/cache@v3
25 | with:
26 | path: ~/.gradle/caches
27 | key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
28 | restore-keys: ${{ runner.os }}-gradle
29 | - name: Build and publish
30 | env:
31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
33 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
34 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
35 | OSSRH_GPG_SECRET_KEY_BASE64: ${{ secrets.OSSRH_GPG_SECRET_KEY_BASE64 }}
36 | OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
37 | run: |
38 | if [ "${{ github.event_name }}" = "pull_request" ]; then
39 | export RELEASE_VERSION=${{ github.event.number }}-PR-SNAPSHOT
40 | echo "Deploying version $RELEASE_VERSION"
41 | ./gradlew -Prelease jar publishToSonatype
42 | else
43 | if [ "${{ github.ref_type }}" = "tag" ]; then
44 | export RELEASE_VERSION=${{ github.ref_name }}
45 | export RELEASE_VERSION=${RELEASE_VERSION:1}
46 | else
47 | export RELEASE_VERSION=${{ github.sha }}-SNAPSHOT
48 | fi
49 | echo "Deploying version $RELEASE_VERSION"
50 | ./gradlew -Prelease jar publishToSonatype closeAndReleaseSonatypeStagingRepository
51 | fi
52 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 | on:
3 | push:
4 | branches:
5 | - master
6 | - beta
7 |
8 | permissions:
9 | contents: read # for checkout
10 |
11 | jobs:
12 | release:
13 | name: Release
14 | runs-on: ubuntu-latest
15 | permissions:
16 | contents: write # to be able to publish a GitHub release
17 | issues: write # to be able to comment on released issues
18 | pull-requests: write # to be able to comment on released pull requests
19 | id-token: write # to enable use of OIDC for npm provenance
20 | steps:
21 | - name: Checkout
22 | uses: actions/checkout@v3
23 | with:
24 | fetch-depth: 0
25 | token: ${{ secrets.CLONE_TOKEN }}
26 | - name: Setup Node.js
27 | uses: actions/setup-node@v3
28 | with:
29 | node-version: "lts/*"
30 | - name: Release
31 | env:
32 | GITHUB_TOKEN: ${{ secrets.CLONE_TOKEN }}
33 | run: npx semantic-release
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | tags:
8 | - v*
9 | pull_request:
10 | branches:
11 | - master
12 |
13 | jobs:
14 | test:
15 | runs-on: ubuntu-latest
16 | steps:
17 | - name: Check out Git repository
18 | uses: actions/checkout@v3
19 | - name: Install Java
20 | uses: actions/setup-java@v3
21 | with:
22 | distribution: 'zulu'
23 | java-version: '17'
24 | - name: Cache SonarCloud packages
25 | uses: actions/cache@v3
26 | with:
27 | path: ~/.sonar/cache
28 | key: ${{ runner.os }}-sonar
29 | restore-keys: ${{ runner.os }}-sonar
30 | - name: Cache Gradle packages
31 | uses: actions/cache@v3
32 | with:
33 | path: ~/.gradle/caches
34 | key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
35 | restore-keys: ${{ runner.os }}-gradle
36 | - name: Build and analyze
37 | env:
38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 | run: ./gradlew test --info
40 | - name: Publish Test Report
41 | uses: mikepenz/action-junit-report@v3
42 | if: success() || failure()
43 | with:
44 | report_paths: '**/build/test-results/test/TEST-*.xml'
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io/api/eclipse,linux,windows,java,maven
2 |
3 | ### Eclipse ###
4 | *.pydevproject
5 | .metadata
6 | .gradle
7 | bin/
8 | tmp/
9 | *.tmp
10 | *.bak
11 | *.swp
12 | *~.nib
13 | local.properties
14 | .settings/
15 | .loadpath
16 |
17 | # Eclipse Core
18 | .project
19 |
20 | # Intellij
21 | .idea/*
22 | !.idea/copyright/profiles_settings.xml
23 | !.idea/copyright/ShapeShift.xml
24 | *.iml
25 |
26 | # External tool builders
27 | .externalToolBuilders/
28 |
29 | # Locally stored "Eclipse launch configurations"
30 | *.launch
31 |
32 | # CDT-specific
33 | .cproject
34 |
35 | # JDT-specific (Eclipse Java Development Tools)
36 | .classpath
37 |
38 | # Java annotation processor (APT)
39 | .factorypath
40 |
41 | # PDT-specific
42 | .buildpath
43 |
44 | # sbteclipse plugin
45 | .target
46 |
47 | # TeXlipse plugin
48 | .texlipse
49 |
50 | # STS (Spring Tool Suite)
51 | .springBeans
52 |
53 |
54 | ### Linux ###
55 | *~
56 |
57 | # KDE directory preferences
58 | .directory
59 |
60 | # Linux trash folder which might appear on any partition or disk
61 | .Trash-*
62 |
63 |
64 | ### Windows ###
65 | # Windows image file caches
66 | Thumbs.db
67 | ehthumbs.db
68 |
69 | # Folder config file
70 | Desktop.ini
71 |
72 | # Recycle Bin used on file shares
73 | $RECYCLE.BIN/
74 |
75 | # Windows Installer files
76 | *.cab
77 | *.msi
78 | *.msm
79 | *.msp
80 |
81 | # Windows shortcuts
82 | *.lnk
83 |
84 |
85 | ### Java ###
86 | *.class
87 |
88 | # Mobile Tools for Java (J2ME)
89 | .mtj.tmp/
90 |
91 | # Package Files #
92 | *.jar
93 | *.war
94 | *.ear
95 |
96 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
97 | hs_err_pid*
98 |
99 |
100 | ### Maven ###
101 | target/
102 | pom.xml.tag
103 | pom.xml.releaseBackup
104 | pom.xml.versionsBackup
105 | pom.xml.next
106 | release.properties
107 | dependency-reduced-pom.xml
108 | buildNumber.properties
109 | .mvn/timing.properties
110 | .flattened-pom.xml
111 |
112 |
113 | ### Mac ###
114 | .DS_Store
115 |
116 | ### Gradle ###
117 | .gradle
118 | **/build/
119 | !src/**/build/
120 |
121 | # Ignore Gradle GUI config
122 | gradle-app.setting
123 |
124 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
125 | !gradle-wrapper.jar
126 |
127 | # Avoid ignore Gradle wrappper properties
128 | !gradle-wrapper.properties
129 |
130 | # Cache of project
131 | .gradletasknamecache
132 |
133 | # Eclipse Gradle plugin generated files
134 | # Eclipse Core
135 | .project
136 | # JDT-specific (Eclipse Java Development Tools)
137 | .classpath
--------------------------------------------------------------------------------
/.idea/copyright/ShapeShift.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.releaserc.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "@semantic-release/commit-analyzer",
4 | "@semantic-release/release-notes-generator",
5 | "@semantic-release/github"
6 | ]
7 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2022 ShapeShift
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.dokka.gradle.DokkaTask
2 | import java.util.*
3 |
4 | plugins {
5 | `java-library`
6 | `maven-publish`
7 | signing
8 | id("org.jetbrains.dokka") version "1.6.0"
9 | id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
10 | }
11 |
12 | if (hasProperty("release")) {
13 | val ossrhUsername = System.getenv("OSSRH_USERNAME")
14 | val ossrhPassword = System.getenv("OSSRH_PASSWORD")
15 | val releaseVersion = System.getenv("RELEASE_VERSION")
16 | group = "dev.krud"
17 | version = releaseVersion
18 | nexusPublishing {
19 | this@nexusPublishing.repositories {
20 | sonatype {
21 | username.set(ossrhUsername)
22 | password.set(ossrhPassword)
23 | nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
24 | snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
25 | }
26 | }
27 | }
28 | }
29 |
30 | allprojects {
31 | repositories {
32 | mavenLocal()
33 | mavenCentral()
34 | }
35 | apply(plugin = "java-library")
36 | apply(plugin = "maven-publish")
37 | apply(plugin = "signing")
38 |
39 | if (hasProperty("release")) {
40 | val releaseVersion = System.getenv("RELEASE_VERSION")
41 | val signingKeyBase64 = System.getenv("OSSRH_GPG_SECRET_KEY_BASE64")
42 | val signingPassword = System.getenv("OSSRH_GPG_SECRET_KEY_PASSWORD")
43 | group = "dev.krud"
44 | version = releaseVersion
45 | val isSnapshot = version.toString().endsWith("-SNAPSHOT")
46 | java {
47 | withJavadocJar()
48 | withSourcesJar()
49 | }
50 |
51 | publishing {
52 | publications.create("maven") {
53 | from(components["java"])
54 | artifactId = project.name
55 |
56 | pom {
57 | name.set(project.name)
58 | description.set("A Kotlin library for intelligent object mapping.")
59 | url.set("https://github.com/krud-dev/shapeshift/shapeshift")
60 | licenses {
61 | license {
62 | name.set("MIT License")
63 | url.set("https://opensource.org/licenses/MIT")
64 | }
65 | }
66 |
67 | developers {
68 | developer {
69 | name.set("KRUD")
70 | email.set("admin@krud.dev")
71 | organization.set("KRUD")
72 | organizationUrl.set("https://www.krud.dev")
73 | }
74 | }
75 |
76 | scm {
77 | connection.set("scm:git:git://github.com/krud-dev/shapeshift.git")
78 | developerConnection.set("scm:git:ssh://git@github.com/krud-dev/shapeshift.git")
79 | url.set("https://github.com/krud-dev/shapeshift")
80 | }
81 | }
82 | }
83 | }
84 |
85 | val javadocTask = tasks.named("javadoc").get()
86 |
87 | tasks.withType {
88 | javadocTask.dependsOn(this)
89 | outputDirectory.set(javadocTask.destinationDir)
90 | }
91 | signing {
92 | val signingKey = signingKeyBase64?.let { decodeBase64(it) }
93 | useInMemoryPgpKeys(
94 | signingKey, signingPassword
95 | )
96 | sign(publishing.publications["maven"])
97 | }
98 | }
99 | }
100 |
101 | fun decodeBase64(base64: String): String {
102 | return String(Base64.getDecoder().decode(base64))
103 | }
104 |
--------------------------------------------------------------------------------
/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
4 | `kotlin-dsl`
5 | }
6 |
7 | repositories {
8 | // Use the plugin portal to apply community plugins in convention plugins.
9 | gradlePluginPortal()
10 | }
11 |
12 | dependencies {
13 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
14 | }
--------------------------------------------------------------------------------
/buildSrc/src/main/kotlin/dev.krud.shapeshift.common-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("jvm")
3 | }
4 |
5 | repositories {
6 | mavenLocal()
7 | maven {
8 | url = uri("https://repo.maven.apache.org/maven2/")
9 | }
10 | }
11 |
12 | dependencies {
13 | // Kotlin
14 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
15 | implementation("org.jetbrains.kotlin:kotlin-reflect")
16 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
17 |
18 | // Misc
19 | api("org.jetbrains:annotations:23.0.0")
20 |
21 | // Test
22 | testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
23 | testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
24 | testImplementation("io.strikt:strikt-core:0.31.0")
25 | }
26 |
27 | tasks.withType {
28 | useJUnitPlatform()
29 | }
--------------------------------------------------------------------------------
/docs/getting_started.md:
--------------------------------------------------------------------------------
1 | # Documentation
2 |
3 | Our documentation moved to a new home [here](https://shapeshift.krud.dev/).
4 |
--------------------------------------------------------------------------------
/example/java/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
4 | `kotlin-dsl`
5 | }
6 |
7 | repositories {
8 | // Use the plugin portal to apply community plugins in convention plugins.
9 | gradlePluginPortal()
10 | mavenCentral()
11 | }
--------------------------------------------------------------------------------
/example/java/buildSrc/src/main/kotlin/dev.krud.shapeshift.examples.java.common-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | java
4 | }
5 |
6 | repositories {
7 | mavenLocal()
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | implementation("dev.krud:shapeshift:0.4.0")
13 | testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
14 | }
15 |
16 | group = "dev.krud.shapeshift.examples.java"
17 | version = "0.0.1-SNAPSHOT"
18 | java.sourceCompatibility = JavaVersion.VERSION_1_8
19 |
20 | tasks.withType {
21 | useJUnitPlatform()
22 | }
--------------------------------------------------------------------------------
/example/java/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/example/java/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/java/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/example/java/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/example/java/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | rootProject.name = "shapeshift-examples-java"
2 | include(":simple-mapping")
3 | include(":transformer-mapping")
4 | include(":spring-mapping")
--------------------------------------------------------------------------------
/example/java/simple-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.java.common-conventions")
4 | application
5 | }
6 |
7 | description = "simple-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.java.Main")
11 | }
--------------------------------------------------------------------------------
/example/java/simple-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget;
14 | import dev.krud.shapeshift.resolver.annotation.MappedField;
15 |
16 | @DefaultMappingTarget(SimpleEntityDisplay.class) // The default target class for the mapping
17 | public class SimpleEntity {
18 | public SimpleEntity(String name, String description, String privateData) {
19 | this.name = name;
20 | this.description = description;
21 | this.privateData = privateData;
22 | }
23 |
24 | @MappedField // This field will be mapped to the "name" field in the target class
25 | private String name;
26 |
27 | @MappedField // This field will be mapped to the "name" field in the target class
28 | private String description;
29 |
30 | // This field will not be mapped to any field in the target class
31 | private String privateData;
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public void setName(String name) {
38 | this.name = name;
39 | }
40 |
41 | public String getDescription() {
42 | return description;
43 | }
44 |
45 | public void setDescription(String description) {
46 | this.description = description;
47 | }
48 |
49 | public String getPrivateData() {
50 | return privateData;
51 | }
52 |
53 | public void setPrivateData(String privateData) {
54 | this.privateData = privateData;
55 | }
56 |
57 | @Override
58 | public String toString() {
59 | return "SimpleEntity{" +
60 | "name='" + name + '\'' +
61 | ", description='" + description + '\'' +
62 | ", privateData='" + privateData + '\'' +
63 | '}';
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/example/java/simple-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntityDisplay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | public class SimpleEntityDisplay {
14 | private String name;
15 | private String description;
16 |
17 | public String getName() {
18 | return name;
19 | }
20 |
21 | public void setName(String name) {
22 | this.name = name;
23 | }
24 |
25 | public String getDescription() {
26 | return description;
27 | }
28 |
29 | public void setDescription(String description) {
30 | this.description = description;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "SimpleEntityDisplay{" +
36 | "name='" + name + '\'' +
37 | ", description='" + description + '\'' +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/example/java/simple-mapping/src/test/java/dev/krud/shapeshift/examples/java/SimpleMappingTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.ShapeShift;
14 | import dev.krud.shapeshift.ShapeShiftBuilder;
15 | import org.junit.jupiter.api.Test;
16 |
17 | import static org.junit.jupiter.api.Assertions.assertEquals;
18 |
19 | class SimpleMappingTests {
20 | @Test
21 | void testSimpleMapping() {
22 | // Initialize ShapeShift with the default configuration
23 | ShapeShift shapeShift = new ShapeShiftBuilder()
24 | .build();
25 | // Initialize a SimpleEntity
26 | SimpleEntity simpleEntity = new SimpleEntity("Test", "Test description", "Test private data");
27 |
28 | // Map the SimpleEntity to a SimpleEntityDisplay using ShapeShift
29 | SimpleEntityDisplay simpleEntityDisplay = shapeShift.map(simpleEntity, SimpleEntityDisplay.class);
30 |
31 | assertEquals(simpleEntity.getName(), simpleEntityDisplay.getName());
32 | assertEquals(simpleEntity.getDescription(), simpleEntityDisplay.getDescription());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/example/java/spring-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | java
4 | id("dev.krud.shapeshift.examples.java.common-conventions")
5 | id("org.springframework.boot") version "2.6.7"
6 | }
7 |
8 | apply(plugin = "io.spring.dependency-management")
9 | repositories {
10 | mavenLocal()
11 | mavenCentral()
12 | }
13 |
14 | dependencies {
15 | implementation("org.springframework.boot:spring-boot-starter")
16 | implementation("dev.krud:spring-boot-starter-shapeshift:0.4.0")
17 | implementation("org.junit.jupiter:junit-jupiter:5.8.1")
18 | testImplementation("org.springframework.boot:spring-boot-starter-test")
19 | }
20 |
21 | group = "dev.krud.shapeshift.examples.java"
22 | description = "spring-mapping"
23 |
24 | springBoot {
25 | mainClass.set("dev.krud.shapeshift.examples.java.SpringMappingApplication")
26 | }
--------------------------------------------------------------------------------
/example/java/spring-mapping/src/main/java/dev/krud/shapeshift/examples/java/BeanTransformer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer;
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext;
15 | import org.springframework.stereotype.Component;
16 |
17 | @Component
18 | public class BeanTransformer implements MappingTransformer {
19 | @Override
20 | public String transform(MappingTransformerContext extends String> mappingTransformerContext) {
21 | return "******";
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/java/spring-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget;
14 | import dev.krud.shapeshift.resolver.annotation.MappedField;
15 |
16 | @DefaultMappingTarget(SimpleEntityDisplay.class) // The default target class for the mapping
17 | public class SimpleEntity {
18 | public SimpleEntity(String name) {
19 | this.name = name;
20 | }
21 |
22 | @MappedField(transformer = BeanTransformer.class) // This field will be mapped to the "name" field in the target class with the BeanTransformer transformer
23 | private String name;
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/example/java/spring-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntityDisplay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | public class SimpleEntityDisplay {
14 | private String name;
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | @Override
25 | public String toString() {
26 | return "SimpleEntityDisplay{" +
27 | "name='" + name + '\'' +
28 | '}';
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/example/java/spring-mapping/src/main/java/dev/krud/shapeshift/examples/java/SpringMappingApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import org.springframework.boot.SpringApplication;
14 | import org.springframework.boot.autoconfigure.SpringBootApplication;
15 |
16 | @SpringBootApplication
17 | public class SpringMappingApplication {
18 | public static void main(String[] args) {
19 | SpringApplication.run(SpringMappingApplication.class, args);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/example/java/spring-mapping/src/test/java/dev/krud/shapeshift/examples/java/SpringMappingTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.ShapeShift;
14 | import org.junit.jupiter.api.Test;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.boot.test.context.SpringBootTest;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertEquals;
19 |
20 | @SpringBootTest
21 | class SpringMappingTests {
22 | @Autowired
23 | private ShapeShift shapeShift;
24 |
25 | @Test
26 | void testBeanTransformer() {
27 | SimpleEntity simpleEntity = new SimpleEntity("Test");
28 | SimpleEntityDisplay simpleEntityDisplay = shapeShift.map(simpleEntity, SimpleEntityDisplay.class);
29 | assertEquals("******", simpleEntityDisplay.getName());
30 | }
31 | }
--------------------------------------------------------------------------------
/example/java/transformer-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.java.common-conventions")
4 | application
5 | }
6 |
7 | description = "transformer-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
11 | }
--------------------------------------------------------------------------------
/example/java/transformer-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget;
14 | import dev.krud.shapeshift.resolver.annotation.MappedField;
15 |
16 | import java.util.Date;
17 |
18 | @DefaultMappingTarget(SimpleEntityDisplay.class) // The default target class for the mapping
19 | public class SimpleEntity {
20 | @MappedField // This field will be mapped to the creationDate field of the target class, and use the DateToLongTransformer implicitly
21 | private Date creationDate;
22 | @MappedField(transformer = StringToCommaSeparatedStringListTransformer.class, mapTo = "stringList") // This field will be mapped to the stringList field of the target class, and use the StringToCommaSeparatedStringListTransformer as it is explicitly specified
23 | private String commaDelimitedString;
24 |
25 | public SimpleEntity(Date creationDate, String commaDelimitedString) {
26 | this.creationDate = creationDate;
27 | this.commaDelimitedString = commaDelimitedString;
28 | }
29 |
30 | public Date getCreationDate() {
31 | return creationDate;
32 | }
33 |
34 | public void setCreationDate(Date creationDate) {
35 | this.creationDate = creationDate;
36 | }
37 |
38 | public String getCommaDelimitedString() {
39 | return commaDelimitedString;
40 | }
41 |
42 | public void setCommaDelimitedString(String commaDelimitedString) {
43 | this.commaDelimitedString = commaDelimitedString;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "SimpleEntity{" +
49 | "creationDate=" + creationDate +
50 | ", commaDelimitedString='" + commaDelimitedString + '\'' +
51 | '}';
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/example/java/transformer-mapping/src/main/java/dev/krud/shapeshift/examples/java/SimpleEntityDisplay.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import java.util.List;
14 |
15 | public class SimpleEntityDisplay {
16 | private Long creationDate;
17 | private List stringList;
18 |
19 | public Long getCreationDate() {
20 | return creationDate;
21 | }
22 |
23 | public void setCreationDate(Long creationDate) {
24 | this.creationDate = creationDate;
25 | }
26 |
27 | public List getStringList() {
28 | return stringList;
29 | }
30 |
31 | public void setStringList(List stringList) {
32 | this.stringList = stringList;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "SimpleEntityDisplay{" +
38 | "creationDate=" + creationDate +
39 | ", stringList=" + stringList +
40 | '}';
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/example/java/transformer-mapping/src/main/java/dev/krud/shapeshift/examples/java/StringToCommaSeparatedStringListTransformer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer;
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext;
15 |
16 | import java.util.Arrays;
17 | import java.util.List;
18 |
19 | public class StringToCommaSeparatedStringListTransformer implements MappingTransformer> {
20 | @Override
21 | public List transform(MappingTransformerContext extends String> mappingTransformerContext) {
22 | if (mappingTransformerContext.getOriginalValue() == null) {
23 | return null;
24 | }
25 | return Arrays.asList(mappingTransformerContext.getOriginalValue().split(","));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/example/java/transformer-mapping/src/test/java/dev/krud/shapeshift/examples/java/TransformerMappingTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.java;
12 |
13 | import dev.krud.shapeshift.MappingTransformerRegistration;
14 | import dev.krud.shapeshift.ShapeShift;
15 | import dev.krud.shapeshift.ShapeShiftBuilder;
16 | import org.junit.jupiter.api.Test;
17 |
18 | import java.util.Arrays;
19 | import java.util.Date;
20 | import java.util.List;
21 |
22 | import static org.junit.jupiter.api.Assertions.assertEquals;
23 |
24 | class TransformerMappingTests {
25 | @Test
26 | void testTransformerMapping() {
27 | // Initialize ShapeShift with a StringToCommaSeparatedStringListTransformer
28 | MappingTransformerRegistration registration = new MappingTransformerRegistration(
29 | String.class,
30 | List.class,
31 | new StringToCommaSeparatedStringListTransformer(),
32 | false
33 | );
34 |
35 | ShapeShift shapeShift = new ShapeShiftBuilder()
36 | .withTransformer(
37 | new MappingTransformerRegistration(
38 | String.class,
39 | List.class,
40 | new StringToCommaSeparatedStringListTransformer(),
41 | false
42 | )
43 | )
44 | .build();
45 | // Initialize a SimpleEntity
46 | SimpleEntity simpleEntity = new SimpleEntity(new Date(1), "Test,Second,Third");
47 |
48 | // Map the SimpleEntity to a SimpleEntityDisplay using ShapeShift
49 | SimpleEntityDisplay simpleEntityDisplay = shapeShift.map(simpleEntity, SimpleEntityDisplay.class);
50 |
51 | assertEquals(1L, simpleEntityDisplay.getCreationDate());
52 | assertEquals(Arrays.asList("Test", "Second", "Third"), simpleEntityDisplay.getStringList());
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.kotlin.common-conventions")
4 | application
5 | }
6 |
7 | description = "advanced-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
11 | }
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/AdvancedChildEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class AdvancedChildEntity(
14 | val childName: String
15 | )
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/AdvancedEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.annotation.DefaultMappingTarget
14 | import dev.krud.shapeshift.annotation.MappedField
15 |
16 | @DefaultMappingTarget(AdvancedEntityDisplay::class)
17 | data class AdvancedEntity(
18 | @MappedField // This field will be mapped to the "name" field in the default target class
19 | @MappedField(target = ReducedAdvancedEntityDisplay::class) // This field will be mapped to the "name" field in the specified target class
20 | val name: String,
21 |
22 | @MappedField(mapFrom = "childName", mapTo = "firstChildName") // This field will be mapped to the "firstChildName" field in the default target class
23 | @MappedField(target = ReducedAdvancedEntityDisplay::class, mapFrom = "childName", mapTo = "firstChildName") // This field will be mapped to the "firstChildName" field in the specified target class
24 | val firstChild: AdvancedChildEntity,
25 |
26 | // This field will not be mapped to ReducdedAdvancedEntityDisplay because it is missing the @MappedField annotation with the corresponding target class
27 | @MappedField(mapFrom = "childName", mapTo = "secondChildName") // This field will be mapped to the "secondChildName" field in the default target class
28 | val secondChild: AdvancedChildEntity
29 | )
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/AdvancedEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class AdvancedEntityDisplay(
14 | val name: String = "",
15 | val firstChildName: String = "",
16 | val secondChildName: String = ""
17 | )
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 |
15 | /**
16 | * This example shows how to use the more advanced features of the ShapeShift
17 | */
18 | fun main() {
19 | // Initialize ShapeShift with the default configuration
20 | val shapeShift = ShapeShiftBuilder()
21 | .build()
22 | // Initialize a AdvancedEntity
23 | val advancedEntity = AdvancedEntity(
24 | name = "Test",
25 | firstChild = AdvancedChildEntity("First Child"),
26 | secondChild = AdvancedChildEntity("Second Child")
27 | )
28 | // Map the AdvancedEntity to a AdvancedEntityDisplay using ShapeShift
29 | val advancedEntityDisplay = shapeShift.map(advancedEntity)
30 | println("AdvancedEntityDisplay: $advancedEntityDisplay")
31 |
32 | // Map the AdvancedEntity to a ReducedAdvancedEntityDisplay using ShapeShift
33 | val reducedAdvancedEntityDisplay = shapeShift.map(advancedEntity)
34 | println("ReducedAdvancedEntityDisplay: $reducedAdvancedEntityDisplay")
35 | }
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/ReducedAdvancedEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class ReducedAdvancedEntityDisplay(
14 | val name: String = "",
15 | val firstChildName: String = ""
16 | )
--------------------------------------------------------------------------------
/example/kotlin/advanced-mapping/src/test/kotlin/dev/krud/shapeshift/examples/kotlin/AdvancedMappingTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 | import org.junit.jupiter.api.Test
15 | import strikt.api.expectThat
16 | import strikt.assertions.isEqualTo
17 |
18 | internal class AdvancedMappingTests {
19 | @Test
20 | fun `test advanced mapping for AdvancedEntityDisplay`() {
21 | val shapeShift = ShapeShift()
22 | val simpleEntity = AdvancedEntity(
23 | "test",
24 | AdvancedChildEntity("first child"),
25 | AdvancedChildEntity("second child")
26 | )
27 | val result = shapeShift.map(simpleEntity)
28 | expectThat(result.name)
29 | .isEqualTo("test")
30 | expectThat(result.firstChildName)
31 | .isEqualTo("first child")
32 | expectThat(result.secondChildName)
33 | .isEqualTo("second child")
34 | }
35 |
36 | @Test
37 | fun `test advanced mapping for ReducedAdvancedEntityDisplay`() {
38 | val shapeShift = ShapeShift()
39 | val simpleEntity = AdvancedEntity(
40 | "test",
41 | AdvancedChildEntity("first child"),
42 | AdvancedChildEntity("second child")
43 | )
44 | val result = shapeShift.map(simpleEntity)
45 | expectThat(result.name)
46 | .isEqualTo("test")
47 | expectThat(result.firstChildName)
48 | .isEqualTo("first child")
49 | }
50 | }
--------------------------------------------------------------------------------
/example/kotlin/buildSrc/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
4 | `kotlin-dsl`
5 | }
6 |
7 | repositories {
8 | // Use the plugin portal to apply community plugins in convention plugins.
9 | gradlePluginPortal()
10 | mavenCentral()
11 | }
12 |
13 | dependencies {
14 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
15 | }
--------------------------------------------------------------------------------
/example/kotlin/buildSrc/src/main/kotlin/dev.krud.shapeshift.examples.kotlin.common-conventions.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | kotlin("jvm")
4 | }
5 |
6 | repositories {
7 | mavenLocal()
8 | mavenCentral()
9 | }
10 |
11 | dependencies {
12 | implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
13 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
14 | implementation("dev.krud:shapeshift:0.4.0")
15 | testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
16 | testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
17 | testImplementation("io.strikt:strikt-core:0.31.0")
18 | }
19 |
20 | group = "dev.krud.shapeshift.examples.kotlin"
21 | version = "0.0.1-SNAPSHOT"
22 | java.sourceCompatibility = JavaVersion.VERSION_1_8
23 |
24 | tasks.withType {
25 | useJUnitPlatform()
26 | }
--------------------------------------------------------------------------------
/example/kotlin/dsl-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.kotlin.common-conventions")
4 | application
5 | }
6 |
7 | description = "dsl-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
11 | }
--------------------------------------------------------------------------------
/example/kotlin/dsl-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 |
15 | /**
16 | * This example shows how to use ShapeShift to map one object to another
17 | */
18 | fun main() {
19 | // Initialize ShapeShift with the default configuration
20 | val shapeShift = ShapeShiftBuilder()
21 | .withMapping {
22 | SimpleEntity::name mappedTo SimpleEntityDisplay::name
23 | SimpleEntity::description mappedTo SimpleEntityDisplay::description
24 | }
25 | .build()
26 | // Initialize a SimpleEntity
27 | val simpleEntity = SimpleEntity(
28 | name = "Test",
29 | description = "Test description",
30 | privateData = "Test private data"
31 | )
32 | // Map the SimpleEntity to a SimpleEntityDisplay using ShapeShift
33 | val simpleEntityDisplay: SimpleEntityDisplay = shapeShift.map(simpleEntity)
34 | println("SimpleEntityDisplay: $simpleEntityDisplay")
35 | }
--------------------------------------------------------------------------------
/example/kotlin/dsl-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class SimpleEntity(
14 | var name: String?,
15 | var description: String?,
16 | var privateData: String?
17 | )
--------------------------------------------------------------------------------
/example/kotlin/dsl-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class SimpleEntityDisplay(
14 | var name: String? = "",
15 | var description: String? = ""
16 | )
--------------------------------------------------------------------------------
/example/kotlin/dsl-mapping/src/test/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleMappingTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.MappingStrategy
14 | import dev.krud.shapeshift.ShapeShiftBuilder
15 | import org.junit.jupiter.api.Test
16 | import strikt.api.expectThat
17 | import strikt.assertions.isEqualTo
18 | import strikt.assertions.isNull
19 |
20 | internal class SimpleMappingTests {
21 | @Test
22 | internal fun `test simple mapping`() {
23 | val simpleEntity = SimpleEntity(
24 | name = "Test",
25 | description = "Test description",
26 | privateData = "Test private data"
27 | )
28 | val shapeShift = ShapeShiftBuilder()
29 | .withMapping {
30 | SimpleEntity::name mappedTo SimpleEntityDisplay::name
31 | SimpleEntity::description mappedTo SimpleEntityDisplay::description
32 | }
33 | .build()
34 |
35 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
36 |
37 | expectThat(result.name)
38 | .isEqualTo("Test")
39 | expectThat(result.description)
40 | .isEqualTo("Test description")
41 | }
42 |
43 | @Test
44 | internal fun `test simple mapping with ad hoc transformer`() {
45 | val simpleEntity = SimpleEntity(
46 | name = "Test",
47 | description = "Test description",
48 | privateData = "Test private data"
49 | )
50 | val shapeShift = ShapeShiftBuilder()
51 | .withMapping {
52 | SimpleEntity::name mappedTo SimpleEntityDisplay::name withTransformer { ctx ->
53 | ctx.originalValue?.uppercase()
54 | }
55 | }
56 | .build()
57 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
58 |
59 | expectThat(result.name)
60 | .isEqualTo("TEST")
61 | }
62 |
63 | @Test
64 | internal fun `test simple mapping with ad hoc decorator`() {
65 | val simpleEntity = SimpleEntity(
66 | name = "Test",
67 | description = "Test description",
68 | privateData = "Test private data"
69 | )
70 | val shapeShift = ShapeShiftBuilder()
71 | .withMapping {
72 | decorate { ctx ->
73 | val (from, to) = ctx
74 | to.name = "decorated"
75 | }
76 | }
77 | .build()
78 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
79 |
80 | expectThat(result.name)
81 | .isEqualTo("decorated")
82 | }
83 |
84 | @Test
85 | internal fun `test simple mapping with ad hoc condition`() {
86 | val simpleEntity = SimpleEntity(
87 | name = "Test",
88 | description = "Test description",
89 | privateData = "Test private data"
90 | )
91 | val shapeShift = ShapeShiftBuilder()
92 | .withMapping {
93 | SimpleEntity::name mappedTo SimpleEntityDisplay::name withCondition {
94 | true
95 | }
96 | SimpleEntity::description mappedTo SimpleEntityDisplay::description withCondition {
97 | false
98 | }
99 | }
100 | .build()
101 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
102 |
103 | expectThat(result.name)
104 | .isEqualTo("Test")
105 | expectThat(result.description)
106 | .isEqualTo("")
107 | }
108 |
109 | @Test
110 | internal fun `test simple mapping with override mapping strategy`() {
111 | val simpleEntity = SimpleEntity(
112 | name = null,
113 | description = "Test description",
114 | privateData = "Test private data"
115 | )
116 | val shapeShift = ShapeShiftBuilder()
117 | .withMapping {
118 | SimpleEntity::name mappedTo SimpleEntityDisplay::name overrideStrategy MappingStrategy.MAP_ALL
119 | }
120 | .build()
121 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
122 |
123 | expectThat(result.name)
124 | .isNull()
125 | }
126 | }
--------------------------------------------------------------------------------
/example/kotlin/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/example/kotlin/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/example/kotlin/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/example/kotlin/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/example/kotlin/settings.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | rootProject.name = "shapeshift-examples-kotlin"
3 | include(":transformer-mapping")
4 | include(":advanced-mapping")
5 | include(":simple-mapping")
6 | include(":dsl-mapping")
7 | include(":spring-mapping")
--------------------------------------------------------------------------------
/example/kotlin/simple-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.kotlin.common-conventions")
4 | application
5 | }
6 |
7 | description = "simple-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
11 | }
--------------------------------------------------------------------------------
/example/kotlin/simple-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 |
15 | /**
16 | * This example shows how to use ShapeShift to map one object to another
17 | */
18 | fun main() {
19 | // Initialize ShapeShift with the default configuration
20 | val shapeShift = ShapeShiftBuilder()
21 | .build()
22 | // Initialize a SimpleEntity
23 | val simpleEntity = SimpleEntity(
24 | name = "Test",
25 | description = "Test description",
26 | privateData = "Test private data"
27 | )
28 | // Map the SimpleEntity to a SimpleEntityDisplay using ShapeShift
29 | val simpleEntityDisplay: SimpleEntityDisplay = shapeShift.map(simpleEntity)
30 | println("SimpleEntityDisplay: $simpleEntityDisplay")
31 | }
--------------------------------------------------------------------------------
/example/kotlin/simple-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget
14 | import dev.krud.shapeshift.resolver.annotation.MappedField
15 |
16 | @DefaultMappingTarget(SimpleEntityDisplay::class) // The default target class for the mapping
17 | data class SimpleEntity(
18 | @MappedField // This field will be mapped to the "name" field in the target class
19 | val name: String,
20 | @MappedField // This field will be mapped to the "name" field in the target class
21 | val description: String,
22 | // This field will not be mapped to any field in the target class
23 | val privateData: String
24 | )
--------------------------------------------------------------------------------
/example/kotlin/simple-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class SimpleEntityDisplay(
14 | val name: String = "",
15 | val description: String = ""
16 | )
--------------------------------------------------------------------------------
/example/kotlin/simple-mapping/src/test/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleMappingTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 | import org.junit.jupiter.api.Test
15 | import strikt.api.expectThat
16 | import strikt.assertions.isEqualTo
17 |
18 | internal class SimpleMappingTests {
19 | @Test
20 | internal fun `test simple mapping`() {
21 | val shapeShift = ShapeShiftBuilder()
22 | .build()
23 | val simpleEntity = SimpleEntity("test", "test description", "private data")
24 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
25 | expectThat(result.name)
26 | .isEqualTo("test")
27 | expectThat(result.description)
28 | .isEqualTo("test description")
29 | }
30 |
31 | @Test
32 | internal fun `test simple mapping with premade destination instance`() {
33 | val shapeShift = ShapeShiftBuilder()
34 | .build()
35 | val simpleEntity = SimpleEntity("test", "test description", "private data")
36 | val result = shapeShift.map(simpleEntity, SimpleEntityDisplay())
37 | expectThat(result.name)
38 | .isEqualTo("test")
39 | expectThat(result.description)
40 | .isEqualTo("test description")
41 | }
42 | }
--------------------------------------------------------------------------------
/example/kotlin/spring-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | java
4 | id("dev.krud.shapeshift.examples.kotlin.common-conventions")
5 | id("org.springframework.boot") version "2.6.7"
6 | kotlin("plugin.spring") version "1.6.21"
7 | }
8 |
9 | apply(plugin = "io.spring.dependency-management")
10 | repositories {
11 | mavenLocal()
12 | mavenCentral()
13 | }
14 |
15 | dependencies {
16 | implementation("org.springframework.boot:spring-boot-starter")
17 | implementation("dev.krud:spring-boot-starter-shapeshift:0.4.0")
18 | testImplementation("org.springframework.boot:spring-boot-starter-test")
19 | }
20 |
21 | group = "dev.krud.shapeshift.examples.kotlin"
22 | description = "spring-mapping"
23 |
24 | springBoot {
25 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
26 | }
--------------------------------------------------------------------------------
/example/kotlin/spring-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/BeanTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 | import org.springframework.stereotype.Component
16 |
17 | // This transformer will be registered by Spring to the ShapeShift instance in the Spring Context
18 | @Component
19 | class BeanTransformer : MappingTransformer {
20 | override fun transform(context: MappingTransformerContext): String? {
21 | return "******"
22 | }
23 | }
--------------------------------------------------------------------------------
/example/kotlin/spring-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 | import org.springframework.beans.factory.InitializingBean
15 | import org.springframework.beans.factory.annotation.Autowired
16 | import org.springframework.boot.autoconfigure.SpringBootApplication
17 | import org.springframework.boot.builder.SpringApplicationBuilder
18 |
19 | @SpringBootApplication
20 | class Main : InitializingBean {
21 | @Autowired
22 | private lateinit var shapeShift: ShapeShift
23 | override fun afterPropertiesSet() {
24 | val simpleEntity = SimpleEntity(
25 | "Test"
26 | )
27 | val simpleEntityDisplay: SimpleEntityDisplay = shapeShift.map(simpleEntity)
28 | println(simpleEntityDisplay)
29 | }
30 | }
31 |
32 | /**
33 | * This example shows how to use ShapeShift in Spring Boot.
34 | */
35 | fun main() {
36 | SpringApplicationBuilder(Main::class.java)
37 | .run()
38 | }
--------------------------------------------------------------------------------
/example/kotlin/spring-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget
14 | import dev.krud.shapeshift.resolver.annotation.MappedField
15 |
16 | @DefaultMappingTarget(SimpleEntityDisplay::class) // The default target class for the mapping
17 | data class SimpleEntity(
18 | @MappedField(transformer = BeanTransformer::class) // This field will be mapped to the "name" field in the target class with the BeanTransformer transformer
19 | val name: String
20 | )
--------------------------------------------------------------------------------
/example/kotlin/spring-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class SimpleEntityDisplay(
14 | val name: String = ""
15 | )
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.examples.kotlin.common-conventions")
4 | application
5 | }
6 |
7 | description = "transformer-mapping"
8 |
9 | application {
10 | mainClass.set("dev.krud.shapeshift.examples.kotlin.MainKt")
11 | }
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 | import java.util.*
15 |
16 | /**
17 | * This example shows how to use ShapeShift to map one object to another using transformers
18 | */
19 | fun main() {
20 | // Initialize ShapeShift with a StringToCommaSeparatedStringListTransformer and a default DateToLongTransformer
21 | val shapeShift = ShapeShiftBuilder()
22 | .withTransformer(StringToCommaSeparatedStringListTransformer())
23 | .build()
24 | // Initialize a SimpleEntity
25 | val simpleEntity = SimpleEntity(
26 | Date(1),
27 | "First,Second,Third"
28 | )
29 | // Map the SimpleEntity to a SimpleEntityDisplay using ShapeShift
30 | val simpleEntityDisplay: SimpleEntityDisplay = shapeShift.map(simpleEntity)
31 | println("SimpleEntityDisplay: $simpleEntityDisplay")
32 | }
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget
14 | import dev.krud.shapeshift.resolver.annotation.MappedField
15 | import java.util.*
16 |
17 | @DefaultMappingTarget(SimpleEntityDisplay::class) // The default target class for the mapping
18 | data class SimpleEntity(
19 | @MappedField
20 | val creationDate: Date, // This field will be mapped to the creationDate field of the target class, and use the DateToLongTransformer implicitly
21 |
22 | @MappedField(transformer = StringToCommaSeparatedStringListTransformer::class, mapTo = "stringList")
23 | val commaDelimitedString: String // This field will be mapped to the stringList field of the target class, and use the StringToCommaSeparatedStringListTransformer as it is explicitly specified
24 | )
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/SimpleEntityDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | data class SimpleEntityDisplay(
14 | val creationDate: Long = 0,
15 | val stringList: List = emptyList()
16 | )
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/src/main/kotlin/dev/krud/shapeshift/examples/kotlin/StringToCommaSeparatedStringListTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToCommaSeparatedStringListTransformer : MappingTransformer> {
17 | override fun transform(context: MappingTransformerContext): List<*>? {
18 | return context.originalValue?.split(",")
19 | }
20 | }
--------------------------------------------------------------------------------
/example/kotlin/transformer-mapping/src/test/kotlin/dev/krud/shapeshift/examples/kotlin/TransformerMappingTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.examples.kotlin
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 | import org.junit.jupiter.api.Test
15 | import strikt.api.expectThat
16 | import strikt.assertions.isEqualTo
17 | import java.util.*
18 |
19 | internal class TransformerMappingTests {
20 | @Test
21 | fun `test mapping with transformer`() {
22 | val shapeShift = ShapeShiftBuilder()
23 | .withTransformer(StringToCommaSeparatedStringListTransformer())
24 | .build()
25 | val simpleEntity = SimpleEntity(
26 | Date(),
27 | "one,two,three"
28 | )
29 | val result: SimpleEntityDisplay = shapeShift.map(simpleEntity)
30 | expectThat(result.creationDate)
31 | .isEqualTo(simpleEntity.creationDate.time)
32 | expectThat(result.stringList)
33 | .isEqualTo(listOf("one", "two", "three"))
34 | }
35 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/krud-dev/shapeshift/a34b7ccecded4ad3307d0fa924ceba085908f968/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/ops/release.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright KRUD 2022
5 | #
6 | # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 | #
8 | # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 | #
10 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 | #
12 |
13 | set -e
14 |
15 | VERSION=$1
16 |
17 | # Exit if git tree is not clean
18 | if [ -n "$(git status --porcelain)" ]; then
19 | echo "Git tree is not clean, aborting release."
20 | exit 1
21 | fi
22 |
23 | # Exit if version is not correct
24 | if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
25 | echo "Version is not correct, aborting release."
26 | exit 1
27 | fi
28 |
29 | # Tag release and publish changelog
30 | ./gradlew -Prelease -Pshapeshift.version=$VERSION clean jar publishAllPublicationsToOSSRHRepository
31 | git tag -a v$VERSION -m "Release v$VERSION"
32 | conventional-changelog -p angular -i CHANGELOG.md -s -r 0
33 | sed -i '' -E "s/.*<\/version>/$VERSION<\/version>/g" README.md
34 | sed -i '' -E "s/dev.krud:shapeshift:([0-9]+\.[0-9]+\.[0-9]+)/dev.krud:shapeshift:$VERSION/g" README.md
35 | git add README.md
36 | git add CHANGELOG.md
37 | git commit -m "chore(release): release v$VERSION"
38 | #git push origin v$VERSION
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | rootProject.name = "shapeshift-parent"
3 | include(":shapeshift")
4 | include(":spring-boot-starter-shapeshift")
--------------------------------------------------------------------------------
/shapeshift/build.gradle.kts:
--------------------------------------------------------------------------------
1 |
2 | plugins {
3 | id("dev.krud.shapeshift.common-conventions")
4 | }
5 |
6 | description = "shapeshift"
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/MappingDecoratorRegistration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift
12 |
13 | import dev.krud.shapeshift.decorator.EmptyDecorator
14 | import dev.krud.shapeshift.decorator.MappingDecorator
15 | import dev.krud.shapeshift.util.ClassPair
16 |
17 | data class MappingDecoratorRegistration(
18 | val fromClazz: Class,
19 | val toClazz: Class,
20 | val decorator: MappingDecorator
21 | ) {
22 | companion object {
23 | val EMPTY = MappingDecoratorRegistration(
24 | Any::class.java,
25 | Any::class.java,
26 | EmptyDecorator
27 | )
28 |
29 | val MappingDecoratorRegistration.id: ClassPair get() = ClassPair(fromClazz, toClazz)
30 |
31 | inline fun MappingDecorator.toRegistration(): MappingDecoratorRegistration {
32 | return MappingDecoratorRegistration(
33 | From::class.java,
34 | To::class.java,
35 | this
36 | )
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/MappingStrategy.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift
12 |
13 | enum class MappingStrategy {
14 | /**
15 | * A strategy that does nothing, used in override mapping strategies when there is no desire to override the default strategy
16 | */
17 | NONE,
18 |
19 | /**
20 | * A strategy that maps all values
21 | */
22 | MAP_ALL,
23 |
24 | /**
25 | * A strategy that maps only the values that are not null
26 | */
27 | MAP_NOT_NULL
28 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/MappingTransformerRegistration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift
12 |
13 | import dev.krud.shapeshift.transformer.EmptyTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformer
15 | import dev.krud.shapeshift.util.ClassPair
16 |
17 | data class MappingTransformerRegistration(
18 | val fromClazz: Class,
19 | val toClazz: Class,
20 | val transformer: MappingTransformer,
21 | val default: Boolean = false
22 | ) {
23 | companion object {
24 | val EMPTY = MappingTransformerRegistration(
25 | Any::class.java,
26 | Any::class.java,
27 | EmptyTransformer,
28 | false
29 | )
30 |
31 | val MappingTransformerRegistration.id: ClassPair get() = ClassPair(fromClazz, toClazz)
32 |
33 | inline fun MappingTransformer.toRegistration(default: Boolean = false): MappingTransformerRegistration {
34 | return MappingTransformerRegistration(
35 | From::class.java,
36 | To::class.java,
37 | this,
38 | default
39 | )
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingCondition.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.condition
12 |
13 | /**
14 | * Represents a mapping condition that can be applied to ShapeShift
15 | * If the condition is not met, the mapping will not be applied
16 | * @param Value the type of the value to be checked
17 | */
18 | fun interface MappingCondition {
19 | /**
20 | * Checks if the condition is met
21 | * @param context The context for the condition
22 | * @return true if the condition is met, false otherwise
23 | */
24 | fun isValid(context: MappingConditionContext): Boolean
25 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/condition/MappingConditionContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.condition
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 |
15 | /**
16 | * The context payload used for [MappingCondition]
17 | */
18 | data class MappingConditionContext(
19 | /**
20 | * The value to be mapped
21 | */
22 | val originalValue: Value?,
23 | /**
24 | * The [ShapeShift] instance used
25 | */
26 | val shapeShift: ShapeShift
27 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/container/ContainerAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2024
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.container
12 |
13 | import java.lang.reflect.Field
14 |
15 | interface ContainerAdapter {
16 |
17 | val containerClazz: Class
18 |
19 | fun getTrueType(field: Field): Class<*>
20 |
21 | fun unwrapValue(container: ContainerType): Any?
22 |
23 | fun wrapValue(value: Any?): ContainerType
24 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/container/OptionalContainerAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2024
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.container
12 |
13 | import dev.krud.shapeshift.util.getGenericAtPosition
14 | import java.lang.reflect.Field
15 | import java.util.*
16 |
17 | class OptionalContainerAdapter: ContainerAdapter> {
18 | override val containerClazz: Class> = Optional::class.java
19 |
20 | override fun getTrueType(field: Field): Class<*> {
21 | return field.getGenericAtPosition(0)
22 | }
23 |
24 | override fun unwrapValue(container: Optional<*>): Any? {
25 | return container.orElse(null)
26 | }
27 |
28 | override fun wrapValue(value: Any?): Optional<*> {
29 | return Optional.ofNullable(value)
30 | }
31 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/EmptyDecorator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.decorator
12 |
13 | object EmptyDecorator : MappingDecorator {
14 | override fun decorate(context: MappingDecoratorContext) {
15 | // This decorator intentionally does nothing
16 | }
17 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecorator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.decorator
12 |
13 | /**
14 | * Represents a decorator that can be applied to ShapeShift
15 | * Decorators run after mappers and contain a reference to both the from object and to object and may apply changes on both
16 | * or run additional actions
17 | * @param From The type of the from object
18 | * @param To The type of the from object
19 | **/
20 | fun interface MappingDecorator {
21 | /**
22 | * Applies the decorator to the from object and to object
23 | * @param context The context for the decorator
24 | */
25 | fun decorate(context: MappingDecoratorContext)
26 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/decorator/MappingDecoratorContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.decorator
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 |
15 | /**
16 | * The context payload used for [MappingDecorator]
17 | */
18 | data class MappingDecoratorContext(
19 | /**
20 | * The from (source) object of the mapping
21 | */
22 | val from: From,
23 | /**
24 | * The to (target) object of the mapping
25 | */
26 | val to: To,
27 | /**
28 | * The [ShapeShift] instance used
29 | */
30 | val shapeShift: ShapeShift
31 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/dsl/KotlinMappingDsl.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.dsl
12 |
13 | /**
14 | * DSL marker for the Kotlin Mapping DSL
15 | */
16 | @DslMarker
17 | internal annotation class KotlinMappingDsl
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/dto/MappingStructure.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 | package dev.krud.shapeshift.dto
11 |
12 | internal class MappingStructure(var sourceClazz: Class<*>, var targetClazz: Class<*>, val resolvedMappedFields: List)
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/dto/ObjectFieldTrio.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.dto
12 |
13 | import java.lang.reflect.Field
14 |
15 | internal data class ObjectFieldTrio(val target: Any, val field: Field, val type: Class<*>)
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/dto/ResolvedMappedField.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.dto
12 |
13 | import dev.krud.shapeshift.MappingStrategy
14 | import dev.krud.shapeshift.condition.MappingCondition
15 | import dev.krud.shapeshift.transformer.base.MappingTransformer
16 | import java.lang.reflect.Field
17 |
18 | data class ResolvedMappedField(
19 | val mapFromCoordinates: List,
20 | val mapToCoordinates: List,
21 | val transformerCoordinates: TransformerCoordinates = TransformerCoordinates.NONE,
22 | val transformer: MappingTransformer<*, *>?,
23 | val conditionClazz: Class>?,
24 | val condition: MappingCondition<*>?,
25 | val overrideMappingStrategy: MappingStrategy?
26 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/dto/TransformerCoordinates.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.dto
12 |
13 | import dev.krud.shapeshift.transformer.EmptyTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformer
15 |
16 | data class TransformerCoordinates(
17 | val type: Class>? = null
18 | ) {
19 | companion object {
20 | val NONE = TransformerCoordinates()
21 | fun ofType(
22 | type: Class>
23 | ): TransformerCoordinates {
24 | if (type == EmptyTransformer::class.java) {
25 | return NONE
26 | }
27 | return TransformerCoordinates(type = type)
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/enums/AutoMappingStrategy.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.enums
12 |
13 | /**
14 | * Auto mapping strategy for supported resolvers
15 | */
16 | enum class AutoMappingStrategy {
17 | /**
18 | * Do not automap, used as a default value
19 | */
20 | NONE,
21 |
22 | /**
23 | * Automap by name irrespective of type
24 | */
25 | BY_NAME,
26 |
27 | /**
28 | * Automap by name and type
29 | */
30 | BY_NAME_AND_TYPE
31 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/MappingDefinition.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.resolver
12 |
13 | import dev.krud.shapeshift.dto.ResolvedMappedField
14 |
15 | data class MappingDefinition(
16 | val fromClazz: Class<*>,
17 | val toClazz: Class<*>,
18 | val resolvedMappedFields: List
19 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/MappingDefinitionResolver.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.resolver
12 |
13 | interface MappingDefinitionResolver {
14 | fun resolve(fromClazz: Class<*>, toClazz: Class<*>): MappingDefinition?
15 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/StaticMappingDefinitionResolver.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.resolver
12 |
13 | class StaticMappingDefinitionResolver(
14 | private val mappingDefinitions: List
15 | ) : MappingDefinitionResolver {
16 | override fun resolve(fromClazz: Class<*>, toClazz: Class<*>): MappingDefinition? {
17 | return mappingDefinitions.find { it.fromClazz == fromClazz && it.toClazz == toClazz }
18 | }
19 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/annotation/AutoMapping.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.resolver.annotation
12 |
13 | import dev.krud.shapeshift.enums.AutoMappingStrategy
14 | import kotlin.reflect.KClass
15 |
16 | @Repeatable
17 | @Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS)
18 | annotation class AutoMapping(val target: KClass<*> = Nothing::class, val strategy: AutoMappingStrategy)
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/annotation/DefaultMappingTarget.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.resolver.annotation
12 |
13 | import kotlin.reflect.KClass
14 |
15 | /**
16 | * Defines a default mapping target for the given type.
17 | * Doing so will make it possible to use [MappedField] without specifying the `target`
18 | */
19 | @Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS)
20 | annotation class DefaultMappingTarget(
21 | /**
22 | * The target type to map to
23 | */
24 | val value: KClass<*>
25 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/resolver/annotation/MappedField.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 | package dev.krud.shapeshift.resolver.annotation
11 |
12 | import dev.krud.shapeshift.MappingStrategy
13 | import dev.krud.shapeshift.condition.MappingCondition
14 | import dev.krud.shapeshift.transformer.EmptyTransformer
15 | import dev.krud.shapeshift.transformer.base.MappingTransformer
16 | import kotlin.reflect.KClass
17 |
18 | /**
19 | * Indicates that an annotated field should be mapped to a field on a different model by the [FieldMapper]
20 | */
21 | @Target(AnnotationTarget.FIELD, AnnotationTarget.CLASS)
22 | @Repeatable
23 | annotation class MappedField(
24 | /**
25 | * The target class to map the field to
26 | */
27 | val target: KClass<*> = Nothing::class,
28 | /**
29 | * (Optional) The field name to map the value from.
30 | * When used at the field level, allows for mapping of nested values
31 | * If left empty at the type level, an exception will be thrown. Otherwise, the name of the field will be used.
32 | */
33 | val mapFrom: String = "",
34 | /**
35 | * (Optional) The field name to map the value to.
36 | * If left empty, the name of the field will be used.
37 | */
38 | val mapTo: String = "",
39 | /**
40 | * The [MappingTransformer] to use on the value
41 | */
42 | val transformer: KClass> = EmptyTransformer::class,
43 |
44 | /**
45 | * The condition to use to determine if the field should be mapped
46 | */
47 | val condition: KClass> = Nothing::class,
48 |
49 | /**
50 | * An override mapping strategy to use in lieu of the default
51 | */
52 | val overrideMappingStrategy: MappingStrategy = MappingStrategy.NONE
53 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/AnyToStringMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class AnyToStringMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): String? {
18 | return context.originalValue?.toString()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/DateToLongMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 | import java.util.*
16 |
17 | class DateToLongMappingTransformer : MappingTransformer {
18 | override fun transform(context: MappingTransformerContext): Long? {
19 | return context.originalValue?.time
20 | }
21 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/EmptyTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | object EmptyTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Any? {
18 | return context.originalValue
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/ImplicitCollectionMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 | import java.lang.reflect.ParameterizedType
16 |
17 | class ImplicitCollectionMappingTransformer : MappingTransformer, Collection> {
18 | override fun transform(context: MappingTransformerContext>): Collection? {
19 | context.originalValue ?: return null
20 | val type = context.toField?.genericType as? ParameterizedType ?: return null
21 | val collectionType = type.actualTypeArguments[0] as? Class<*> ?: return null
22 | val baseMapping = context.originalValue.map { context.shapeShift.map(it, collectionType) }
23 | return when (collectionType.kotlin) {
24 | List::class -> {
25 | baseMapping
26 | }
27 | MutableList::class -> {
28 | baseMapping.toMutableList()
29 | }
30 | Set::class -> {
31 | baseMapping.toSet()
32 | }
33 | MutableSet::class -> {
34 | baseMapping.toMutableSet()
35 | }
36 | else -> {
37 | baseMapping
38 | }
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/ImplicitMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class ImplicitMappingTransformer() : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Any? {
18 | context.originalValue ?: return null
19 | return context.shapeShift.map(context.originalValue, context.toField.type)
20 | }
21 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/LongToDateMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 | import java.util.*
16 |
17 | class LongToDateMappingTransformer : MappingTransformer {
18 | override fun transform(context: MappingTransformerContext): Date? {
19 | context.originalValue ?: return null
20 | return Date(context.originalValue)
21 | }
22 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToCharMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToCharMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Char? {
18 | return context.originalValue?.toChar()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToDoubleMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToDoubleMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Double? {
18 | return context.originalValue?.toDouble()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToFloatMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToFloatMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Float? {
18 | return context.originalValue?.toFloat()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToIntMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToIntMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Int? {
18 | return context.originalValue?.toInt()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToLongMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToLongMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Long? {
18 | return context.originalValue?.toLong()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/NumberToShortMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class NumberToShortMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Short? {
18 | context.originalValue ?: return null
19 | return context.originalValue?.toShort()
20 | }
21 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToBooleanMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToBooleanMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Boolean? {
18 | return context.originalValue?.toBooleanStrict()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToCharMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToCharMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Char? {
18 | context.originalValue ?: return null
19 | val charArray = context.originalValue.toCharArray()
20 | if (charArray.size != 1) {
21 | throw IllegalArgumentException("String must be of size 1")
22 | }
23 | return context.originalValue?.toCharArray()?.first()
24 | }
25 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToDoubleMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToDoubleMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Double? {
18 | return context.originalValue?.toDouble()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToFloatMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToFloatMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Float? {
18 | return context.originalValue?.toFloat()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToIntMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToIntMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Int? {
18 | return context.originalValue?.toInt()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToLongMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToLongMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Long? {
18 | return context.originalValue?.toLong()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/StringToShortMappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.transformer.base.MappingTransformer
14 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
15 |
16 | class StringToShortMappingTransformer : MappingTransformer {
17 | override fun transform(context: MappingTransformerContext): Short? {
18 | return context.originalValue?.toShort()
19 | }
20 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer.base
12 |
13 | fun interface MappingTransformer {
14 | fun transform(context: MappingTransformerContext): To?
15 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/transformer/base/MappingTransformerContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer.base
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 | import java.lang.reflect.Field
15 |
16 | data class MappingTransformerContext(
17 | val originalValue: From?,
18 | val fromObject: Any,
19 | val toObject: Any,
20 | val fromField: Field,
21 | val toField: Field,
22 | val shapeShift: ShapeShift
23 | )
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/util/AutoMappingUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.util
12 |
13 | import dev.krud.shapeshift.dto.ResolvedMappedField
14 | import dev.krud.shapeshift.dto.TransformerCoordinates
15 | import dev.krud.shapeshift.enums.AutoMappingStrategy
16 |
17 | internal fun getAutoMappings(fromClazz: Class, toClazz: Class, strategy: AutoMappingStrategy): List {
18 | val resolvedMappedFields = mutableListOf()
19 | if (strategy != AutoMappingStrategy.NONE) {
20 | val fromFields = fromClazz.getDeclaredFieldsRecursive()
21 | val toFields = toClazz.getDeclaredFieldsRecursive()
22 | for (fromField in fromFields) {
23 | val toField = toFields.find {
24 | when (strategy) {
25 | AutoMappingStrategy.BY_NAME -> it.name == fromField.name
26 | AutoMappingStrategy.BY_NAME_AND_TYPE -> it.name == fromField.name && it.type.kotlin.javaObjectType == fromField.type.kotlin.javaObjectType
27 | else -> error("Unsupported auto mapping strategy")
28 | }
29 | } ?: continue
30 | resolvedMappedFields += ResolvedMappedField(
31 | listOf(fromField),
32 | listOf(toField),
33 | TransformerCoordinates.NONE,
34 | null,
35 | null,
36 | null,
37 | null
38 | )
39 | }
40 | }
41 | return resolvedMappedFields
42 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/util/MapUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.util
12 |
13 | import java.util.concurrent.ConcurrentHashMap
14 | import java.util.concurrent.ConcurrentMap
15 |
16 | internal inline fun concurrentMapOf(): ConcurrentMap = ConcurrentHashMap()
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/util/ReflectionUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | @file:JvmName("ReflectionUtils")
12 |
13 | package dev.krud.shapeshift.util
14 |
15 | import java.lang.reflect.Field
16 | import java.lang.reflect.ParameterizedType
17 |
18 |
19 | data class ClassPair(val from: Class, val to: Class)
20 |
21 | internal fun Field.getValue(target: Any): Any? {
22 | return this.get(target)
23 | }
24 |
25 | internal fun Field.setValue(target: Any, value: Any?) {
26 | this.set(target, value)
27 | }
28 |
29 | internal fun Class<*>.getDeclaredFieldsRecursive(): List {
30 | var clazz: Class<*>? = this
31 | val fields = mutableListOf()
32 | while (clazz != null) {
33 | fields += clazz.declaredFields
34 | clazz = clazz.superclass
35 | }
36 |
37 | return fields
38 | }
39 |
40 | internal fun Class<*>.getDeclaredFieldRecursive(name: String): Field {
41 | var clazz: Class<*>? = this
42 | while (clazz != null) {
43 | try {
44 | return clazz.getDeclaredField(name)
45 | } catch (e: NoSuchFieldException) {
46 | clazz = clazz.superclass
47 | }
48 | }
49 | throw NoSuchFieldException(name)
50 | }
51 |
52 | internal fun Field.getGenericAtPosition(position: Int): Class<*> {
53 | if (genericType !is ParameterizedType) {
54 | error("Type ${this.type} is not parameterized")
55 | }
56 | val typeArgument = (genericType as ParameterizedType).actualTypeArguments[position] as Class<*>
57 | return typeArgument
58 | }
--------------------------------------------------------------------------------
/shapeshift/src/main/kotlin/dev/krud/shapeshift/util/StringUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.util
12 |
13 | internal fun CharSequence.splitIgnoreEmpty(vararg delimiters: String): List {
14 | return this.split(*delimiters).filter {
15 | it.isNotEmpty()
16 | }
17 | }
--------------------------------------------------------------------------------
/shapeshift/src/test/kotlin/dev/krud/shapeshift/ShapeShiftBuilderTests.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift
12 |
13 | import org.junit.jupiter.api.Test
14 | import strikt.api.expectThrows
15 |
16 | class ShapeShiftBuilderTests {
17 | @Test
18 | internal fun `ShapeShiftBuilder should throw exception if default mapping strategy is NONE`() {
19 | val shapeShiftBuilder = ShapeShiftBuilder()
20 | .withDefaultMappingStrategy(MappingStrategy.NONE)
21 |
22 | expectThrows {
23 | shapeShiftBuilder.build()
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/shapeshift/src/test/kotlin/dev/krud/shapeshift/ValueContainerTest.kt:
--------------------------------------------------------------------------------
1 | package dev.krud.shapeshift
2 |
3 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget
4 | import dev.krud.shapeshift.resolver.annotation.MappedField
5 | import org.junit.jupiter.api.BeforeEach
6 | import org.junit.jupiter.api.Test
7 | import strikt.api.expect
8 | import strikt.assertions.isEqualTo
9 | import java.util.*
10 | import javax.swing.text.html.Option
11 |
12 | class ValueContainerTest {
13 |
14 | internal lateinit var shapeShift: ShapeShift
15 |
16 | @BeforeEach
17 | internal fun setUp() {
18 | shapeShift = ShapeShiftBuilder().build()
19 | }
20 |
21 | @Test
22 | fun `contained values should be unwrapped, transformed and rewrapped`() {
23 | val toWrapped = shapeShift.map(FromWrapped())
24 | expect {
25 | that(toWrapped.someField).isEqualTo(Optional.of("ABCD"))
26 | that(toWrapped.someField2).isEqualTo(Optional.of(123))
27 | }
28 | }
29 |
30 | @Test
31 | fun `empty but non-null container should set null`() {
32 | val toNullable = shapeShift.map(FromNullable())
33 | println()
34 | }
35 |
36 |
37 | @DefaultMappingTarget(ToWrapped::class)
38 | class FromWrapped {
39 | @MappedField
40 | var someField: Optional? = Optional.of("ABCD")
41 |
42 | @MappedField
43 | var someField2: Optional? = Optional.of("123")
44 | }
45 |
46 | class ToWrapped {
47 | var someField: Optional? = null
48 | var someField2: Optional? = null
49 | }
50 |
51 | @DefaultMappingTarget(ToNullable::class)
52 | class FromNullable {
53 | @MappedField
54 | var someField: Optional? = Optional.empty()
55 | @MappedField
56 | var someField2: Optional? = null
57 | }
58 |
59 | class ToNullable {
60 | var someField: String? = "ABCD"
61 | var someField2: String? = "ABCD"
62 | }
63 | }
--------------------------------------------------------------------------------
/shapeshift/src/test/kotlin/dev/krud/shapeshift/transformer/_fixtures.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.transformer
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 | import dev.krud.shapeshift.resolver.annotation.DefaultMappingTarget
15 | import dev.krud.shapeshift.resolver.annotation.MappedField
16 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
17 | import kotlin.reflect.jvm.javaField
18 |
19 | class ExampleObject {
20 | var name: String? = null
21 | }
22 |
23 | @DefaultMappingTarget(ImplicitCollectionTo::class)
24 | data class ImplicitCollectionFrom(
25 | @MappedField(transformer = ImplicitCollectionMappingTransformer::class)
26 | val fromChildren: List = emptyList()
27 | ) {
28 | @DefaultMappingTarget(ImplicitCollectionTo.ToChild::class)
29 | data class FromChild(
30 | @MappedField
31 | val value: String? = null
32 | )
33 | }
34 |
35 | data class ImplicitCollectionTo(
36 | val toChildren: List = emptyList()
37 | ) {
38 | data class ToChild(
39 | val value: String? = null
40 | )
41 | }
42 |
43 | fun mockMappingTransformerContext(value: From?): MappingTransformerContext {
44 | return MappingTransformerContext(
45 | value,
46 | ExampleObject(),
47 | ExampleObject(),
48 | ExampleObject::name.javaField!!,
49 | ExampleObject::name.javaField!!,
50 | ShapeShiftBuilder().build()
51 | )
52 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.springframework.boot.gradle.tasks.bundling.BootJar
2 | import org.springframework.boot.gradle.tasks.run.BootRun
3 |
4 | plugins {
5 | id("dev.krud.shapeshift.common-conventions")
6 | kotlin("plugin.spring") version "1.6.0"
7 | id("org.springframework.boot") version "2.6.7"
8 | }
9 |
10 | apply(plugin = "io.spring.dependency-management")
11 |
12 | dependencies {
13 | implementation(project(":shapeshift"))
14 | implementation("org.springframework:spring-core")
15 | implementation("org.springframework:spring-beans")
16 | implementation("org.springframework:spring-context")
17 | implementation("org.springframework.boot:spring-boot-autoconfigure")
18 | testImplementation("org.springframework.boot:spring-boot-starter-test")
19 | }
20 |
21 | tasks.named("bootJar") {
22 | enabled = false
23 | }
24 |
25 | tasks.named("bootRun") {
26 | enabled = false
27 | }
28 |
29 | tasks.named("jar") {
30 | enabled = true
31 | archiveClassifier.set("")
32 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/main/kotlin/dev/krud/shapeshift/spring/ShapeShiftAutoConfiguration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 | import dev.krud.shapeshift.ShapeShiftBuilder
15 | import dev.krud.shapeshift.spring.customizer.ShapeShiftDecoratorCustomizer
16 | import dev.krud.shapeshift.spring.customizer.ShapeShiftTransformerCustomizer
17 | import org.springframework.beans.factory.annotation.Autowired
18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
19 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
20 | import org.springframework.context.annotation.Bean
21 | import org.springframework.context.annotation.Configuration
22 |
23 | @Configuration
24 | @ConditionalOnClass(ShapeShift::class)
25 | class ShapeShiftAutoConfiguration {
26 | @Bean
27 | @ConditionalOnMissingBean(ShapeShift::class)
28 | fun shapeShift(@Autowired(required = false) customizers: List?): ShapeShift {
29 | val builder = ShapeShiftBuilder()
30 | customizers?.forEach { customizer ->
31 | customizer.customize(builder)
32 | }
33 | return builder.build()
34 | }
35 |
36 | @Bean
37 | fun shapeShiftTransformerCustomizer() = ShapeShiftTransformerCustomizer()
38 |
39 | @Bean
40 | fun shapeShiftDecoratorCustomizer() = ShapeShiftDecoratorCustomizer()
41 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/main/kotlin/dev/krud/shapeshift/spring/ShapeShiftBuilderCustomizer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring
12 |
13 | import dev.krud.shapeshift.ShapeShiftBuilder
14 |
15 | /**
16 | * The customizer allows you to customize the [ShapeShiftBuilder] before it is used to create the [ShapeShift] bean.
17 | */
18 | interface ShapeShiftBuilderCustomizer {
19 | /**
20 | * Customize the [ShapeShiftBuilder] before it is used to create the [ShapeShift] bean.
21 | */
22 | fun customize(builder: ShapeShiftBuilder)
23 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/main/kotlin/dev/krud/shapeshift/spring/customizer/ShapeShiftDecoratorCustomizer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring.customizer
12 |
13 | import dev.krud.shapeshift.MappingDecoratorRegistration
14 | import dev.krud.shapeshift.ShapeShiftBuilder
15 | import dev.krud.shapeshift.decorator.MappingDecorator
16 | import dev.krud.shapeshift.spring.ShapeShiftBuilderCustomizer
17 | import org.springframework.beans.factory.annotation.Autowired
18 | import org.springframework.context.annotation.Configuration
19 | import org.springframework.core.GenericTypeResolver
20 |
21 | @Configuration
22 | class ShapeShiftDecoratorCustomizer : ShapeShiftBuilderCustomizer {
23 | @Autowired(required = false)
24 | private val mappingDecorators: List>? = null
25 |
26 | override fun customize(builder: ShapeShiftBuilder) {
27 | mappingDecorators?.forEach { mappingDecorator ->
28 | val types = GenericTypeResolver.resolveTypeArguments(mappingDecorator::class.java, MappingDecorator::class.java)
29 | builder.withDecorator(
30 | MappingDecoratorRegistration(
31 | types[0] as Class,
32 | types[1] as Class,
33 | mappingDecorator as MappingDecorator
34 | )
35 | )
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/main/kotlin/dev/krud/shapeshift/spring/customizer/ShapeShiftTransformerCustomizer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring.customizer
12 |
13 | import dev.krud.shapeshift.MappingTransformerRegistration
14 | import dev.krud.shapeshift.ShapeShiftBuilder
15 | import dev.krud.shapeshift.spring.ShapeShiftBuilderCustomizer
16 | import dev.krud.shapeshift.transformer.base.MappingTransformer
17 | import org.springframework.beans.factory.annotation.Autowired
18 | import org.springframework.context.annotation.Configuration
19 | import org.springframework.core.GenericTypeResolver
20 |
21 | @Configuration
22 | class ShapeShiftTransformerCustomizer : ShapeShiftBuilderCustomizer {
23 | @Autowired(required = false)
24 | private val mappingTransformers: List>? = null
25 |
26 | override fun customize(builder: ShapeShiftBuilder) {
27 | mappingTransformers?.forEach { mappingTransformer ->
28 | val types = GenericTypeResolver.resolveTypeArguments(mappingTransformer::class.java, MappingTransformer::class.java)
29 | val registration = MappingTransformerRegistration(
30 | types!![0] as Class,
31 | types[1] as Class,
32 | mappingTransformer as MappingTransformer,
33 | false
34 | )
35 | builder.withTransformer(
36 | registration
37 | )
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
2 | dev.krud.shapeshift.spring.ShapeShiftAutoConfiguration
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/test/kotlin/dev/krud/shapeshift/spring/ShapeShiftSpringTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring
12 |
13 | import dev.krud.shapeshift.ShapeShift
14 | import org.junit.jupiter.api.Test
15 | import org.junit.jupiter.api.extension.ExtendWith
16 | import org.springframework.beans.factory.annotation.Autowired
17 | import org.springframework.test.context.ContextConfiguration
18 | import org.springframework.test.context.junit.jupiter.SpringExtension
19 | import strikt.api.expectThat
20 | import strikt.assertions.contains
21 |
22 | @ExtendWith(SpringExtension::class)
23 | @ContextConfiguration(classes = [ShapeShiftAutoConfiguration::class, TestConfiguration::class])
24 | internal class ShapeShiftSpringTest {
25 | @Autowired
26 | private lateinit var shapeShift: ShapeShift
27 |
28 | @Autowired
29 | private lateinit var exampleDecorator: ExampleDecorator
30 |
31 | @Autowired
32 | private lateinit var exampleTransformer: ExampleTransformer
33 |
34 | @Test
35 | internal fun `context loads`() {
36 | println()
37 | }
38 |
39 | @Test
40 | internal fun `bean transformer is loaded`() {
41 | expectThat(shapeShift.transformerRegistrations.map { it.transformer })
42 | .contains(exampleTransformer)
43 | }
44 |
45 | @Test
46 | internal fun `bean decorator is loaded`() {
47 | expectThat(shapeShift.decoratorRegistrations.map { it.decorator })
48 | .contains(exampleDecorator)
49 | }
50 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/test/kotlin/dev/krud/shapeshift/spring/TestConfiguration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring
12 |
13 | import org.springframework.context.annotation.Bean
14 | import org.springframework.context.annotation.Configuration
15 |
16 | @Configuration
17 | class TestConfiguration {
18 | @Bean
19 | fun exampleTransformer(): ExampleTransformer {
20 | return ExampleTransformer()
21 | }
22 |
23 | @Bean
24 | fun exampleDecorator() = ExampleDecorator()
25 | }
--------------------------------------------------------------------------------
/spring-boot-starter-shapeshift/src/test/kotlin/dev/krud/shapeshift/spring/_fixtures.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright KRUD 2022
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 | *
6 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 | */
10 |
11 | package dev.krud.shapeshift.spring
12 |
13 | import dev.krud.shapeshift.decorator.MappingDecorator
14 | import dev.krud.shapeshift.decorator.MappingDecoratorContext
15 | import dev.krud.shapeshift.transformer.base.MappingTransformer
16 | import dev.krud.shapeshift.transformer.base.MappingTransformerContext
17 |
18 | class ExampleClass
19 |
20 | class SecondExampleClass
21 |
22 | class ExampleDecorator : MappingDecorator {
23 | override fun decorate(context: MappingDecoratorContext) {
24 | }
25 | }
26 |
27 | class ExampleTransformer : MappingTransformer {
28 | override fun transform(context: MappingTransformerContext): String? {
29 | return context.originalValue
30 | }
31 | }
--------------------------------------------------------------------------------