Open MattiasMartens opened 4 days ago
You could currently solve it like this:
// goverter:converter
type Converter interface {
// goverter:map . EntityLocation
ConvertIngestableToMyEntity(source Ingestable) MyEntity
// goverter:map . LocationDesignator
ConvertIngestableToEntityLocation(source Ingestable) EntityLocation
// goverter:map EntityLocationDesignationShortCode LocationShortCode
// goverter:map EntityLocationDesignationLongCode LocationLongCode
ConvertIngestableToLocationDesignator(source Ingestable) LocationDesignator
}
With
// goverter:map . EntityLocation
ConvertIngestableToMyEntity(source Ingestable) MyEntity
you basically say, may Ingestable to tho EntityLocation property of type EntityLocation. Now goverter tries to convert Ingestable -> EntityLocation, sees another user defined method ConvertIngestableToEntityLocation(source Ingestable) EntityLocation
and uses that one.
It should be possible to support nested path on as TARGET in goverter:map, but there are some edge-cases that are difficult and need thinking how they should be implemented. The feature is requested in #80.
Have you read the project documentation?
Describe your question
This question is half "how do I do this" and half "what are the nature of the limitations".
I am trying to write a converter that describes how to map one field to another. The nature of the mapping is that a field on my source object drives a field on another object that is embedded more than one layer deep.
I know the goverter mapping does not allow targets as paths but I am struggling to understand what the proper solution here is.
Per the documentation, it seems the case I'm in is "un-flattening" and the suggestion is to use map DOT TARGET; but unless I’m greatly misunderstanding something, that only works when the target fields are nested exactly one level deep and have the same names.
Source code
I know I can solve my problem by specifying a mapping function, but: