Skip to content

feat: Support custom file name mappings#190

Merged
jinzhu merged 4 commits into
jinzhu:masterfrom
driventokill:feature/custom-field-names
Aug 9, 2023
Merged

feat: Support custom file name mappings#190
jinzhu merged 4 commits into
jinzhu:masterfrom
driventokill:feature/custom-field-names

Conversation

@driventokill

@driventokill driventokill commented Aug 8, 2023

Copy link
Copy Markdown
Contributor

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 driventokill force-pushed the feature/custom-field-names branch from 53ea514 to 7d39583 Compare August 8, 2023 18:21
@driventokill

Copy link
Copy Markdown
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
@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