Skip to content
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

feat: Support custom file name mappings #190

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

driventokill
Copy link
Contributor

@driventokill driventokill commented Aug 8, 2023

Custom field name mappings to copy values with different names in fromValue and toValue types. Examples can be found in copier_different_field_name_test.go.

resolve #139

type User1 struct {
	Id      int64
	Name    string
	Address []string
}

type User2 struct {
	Id2      int64
	Name2    string
	Address2 []string
}

u1 := User1{Id: 1, Name: "1", Address: []string{"1"}}
var u2 User2
err := copier.CopyWithOption(&u2, u1, copier.Option{FieldNameMapping: []copier.FieldNameMapping{
	{SrcType: u1, DstType: u2,
		Mapping: map[string]string{
			"Id":      "Id2",
			"Name":    "Name2",
			"Address": "Address2"}},
}})

@driventokill driventokill force-pushed the feature/custom-field-names branch 2 times, most recently from 89d4fb2 to 53ea514 Compare August 8, 2023 18:13
Custom field name mappings to copy values with different names in `fromValue` and `toValue` types.
Examples can be found in `copier_different_field_name_test.go`.
@driventokill
Copy link
Contributor Author

@jinzhu The failed cases seem like been broken since f036a42 (Merge pull request #178 from QianChenglong/master)

@jinzhu jinzhu merged commit 70b1d4e into jinzhu:master Aug 9, 2023
10 checks passed
@driventokill driventokill deleted the feature/custom-field-names branch August 9, 2023 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在无法修改tag的情况下,如何复制两个不同名的字段?
2 participants