-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added case insensitive fields mapping #18
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
19aeca2
Added case sensivity handling
KamilMrowiec 20bb270
Added tests
KamilMrowiec 33e33bc
Added example
KamilMrowiec a85264d
Added checking for duplicated fields in case insensitive mapper
KamilMrowiec e332612
Added documentation
KamilMrowiec eced6cd
Added more tests
KamilMrowiec 31d882c
Updated example
KamilMrowiec a9a90b7
Merge commit 'c8e1c2022e3e2ba76a34fa547a28bbeac2327737' into feature/…
KamilMrowiec f36f581
Merge pull request #1 from Antriadus/feature/case_insenstive
Antriadus 199f456
Updated versions
KamilMrowiec cb79491
Updated CHANGELOG.md
KamilMrowiec 14708ab
Updated path to example
KamilMrowiec ce33f30
Repaired packege sources
KamilMrowiec f93185f
Merge branch 'master' of https://github.com/smotastic/smartstruct int…
KamilMrowiec 2ee0a5a
Merge branch 'smotastic-master'
KamilMrowiec 22dda7f
Added CustomMapping annotation
KamilMrowiec c0f9207
First working version of custom mapping
KamilMrowiec da1e908
Working on mapper generator
KamilMrowiec f171927
Repaired case_senstive example
KamilMrowiec 3a68627
Added custom mapping test
KamilMrowiec 02ed035
Connected custom mapping tests
KamilMrowiec da6a2de
Added custom mapping example
KamilMrowiec 97da9e7
Added string list extensions
KamilMrowiec 106c09e
Repaired custom_mapping tests
KamilMrowiec 37a85b6
Repaired custom mapping
KamilMrowiec fcad6a1
Updated custom_mapping test
KamilMrowiec fbd6500
Added examples
KamilMrowiec ca7600a
Merge branch 'master' of https://github.com/smotastic/smartstruct int…
KamilMrowiec ebe8005
Merge branch 'master' of https://github.com/smotastic/smartstruct
KamilMrowiec 35cd7b9
Merge commit 'ebe80053da6f8edbb588e82a9bd585dc9e70d8cf' into feature/…
KamilMrowiec 79dd55e
Merge pull request #4 from Antriadus/feature/custom-field
Antriadus 7c0b80e
Repaired test
KamilMrowiec 657a1fc
Removed unecessary StringListExtensions
KamilMrowiec e223a29
Updated examples
KamilMrowiec de3a740
Merge branch 'master' into master
smotastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:smartstruct/smartstruct.dart'; | ||
part 'case_sensitive.mapper.g.dart'; | ||
|
||
class Source { | ||
final String userName; | ||
|
||
Source(this.userName); | ||
} | ||
|
||
class Target { | ||
final String username; | ||
|
||
Target({required this.username}); | ||
} | ||
|
||
@Mapper(caseSensitiveFields: false) | ||
abstract class ExampleMapper { | ||
Target fromSource(Source source); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:smartstruct/smartstruct.dart'; | ||
|
||
part 'custom_mapping.mapper.g.dart'; | ||
|
||
class Source { | ||
final String firstName; | ||
final String lastName; | ||
final String birthDate; | ||
final String avatar; | ||
|
||
Source( | ||
this.firstName, | ||
this.lastName, | ||
this.birthDate, | ||
this.avatar, | ||
); | ||
} | ||
|
||
class Target { | ||
final String fullName; | ||
final DateTime birthDate; | ||
final String avatar; | ||
|
||
Target( | ||
this.fullName, | ||
this.birthDate, | ||
this.avatar, | ||
); | ||
} | ||
|
||
// To have type safety you need extend CustomMapping generic class with specific types. | ||
class DateTimeFromSourceMapper extends CustomMapping<DateTime, Source> { | ||
const DateTimeFromSourceMapper( | ||
{required String targetField, required DateTime Function(Source) f}) | ||
: super(targetField: targetField, f: f); | ||
} | ||
|
||
// It is type safety way. It must be top level function. | ||
DateTime mapBirthDate(Source input) => DateTime.parse(input.birthDate); | ||
|
||
// This is not type safe way, but you don't need to override CustomMapping. It must be top level function. | ||
dynamic mapFullName(dynamic input) { | ||
final castedInput = input as Source; | ||
return '${castedInput.firstName} ${castedInput.lastName}'; | ||
} | ||
|
||
@Mapper() | ||
abstract class CustomMapper { | ||
@DateTimeFromSourceMapper(targetField: "birthDate", f: mapBirthDate) | ||
@CustomMapping(targetField: "fullName", f: mapFullName) | ||
Target fromSource(Source source); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only constructor parameters are paid attention to by the generator.
If i change the Target class in the example custom_mapping.dart to the following.
With the custom mapping of birthdate (not changed)
The birthDate is ignored by the generator.