Open goghcrow opened 1 year ago
You can already achieve the same generated code by doing the following:
// goverter:converter
type Converter interface {
// goverter:map . Address
Convert(FlatPerson) Person
// goverter:map Street StreetName
ConvertAddress(FlatPerson) Address
}
Sadly your solution isn't that easy, because it can clash with other definitions, imagine a converter like this
// goverter:converter
type Converter interface {
// goverter:map . Address
// goverter:map Street Address.StreetName
Convert(FlatPerson) Person
// goverter:map Name StreetName
ConvertAddress(FlatPerson) Address
}
What should be the value for StreetName (Name or Street). I'm not fully against a change like this, but goverter must fail with a readable error when there are conflicting definitions.
It still don't work when FlatPerson is ptr. It's a simplified version of my actual scenario.
// goverter:converter
type Converter interface {
// goverter:map . Address
Convert(*FlatPerson) *Person
// goverter:map Street StreetName
ConvertAddress(*FlatPerson) Address
}
| *github.com/jmattheis/goverter/example/nested.FlatPerson
|
| | github.com/jmattheis/goverter/example/nested.FlatPerson
| |
| | | goverter:map . Address
| | |
| | |
| | |
source*. .???
target*.Address.StreetName
| | | |
| | | | string
| | |
| | | github.com/jmattheis/goverter/example/nested.Address
| |
| | github.com/jmattheis/goverter/example/nested.Person
|
| *github.com/jmattheis/goverter/example/nested.Person
Try defining it as
// goverter:map Street StreetName
ConvertAddress(FlatPerson) Address
See the mapping in the error message. It first does source*
which is a non pointer and then the goverter:map . Address
is used.
When I Combine automap and fieldmap, it doesn't work
the error message was as follows
The solution might be to add the sub context when createing subMethod PR
It works fine.
It works fine, too, and even handles nested cases. But I don't know if there are any other problems
generated
Please :+1: this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.