gocarina / gocsv

The GoCSV package aims to provide easy CSV serialization and deserialization to the golang programming language
MIT License
1.99k stars 245 forks source link

Allow clashing field names of nested structs to be overridden with custom unmarshalers #222

Closed nmlgc closed 2 years ago

nmlgc commented 2 years ago

This comes down to not exposing the field names of nested structs as a fieldInfo if the struct implements UnmarshalText or UnmarshalCSV. https://github.com/gocarina/gocsv/commit/eeb477f6ec9dd44065df8d0960bc9ef37f4153ea already prevented the same if the struct implements MarshalCSV or MarshalText, but I would say that this should also be the case if just one or both of the unmarshaling methods are defined.

Otherwise, an exported field from a nested structure will shadow the intended unmarshaling behavior of the top-level structure if one of its fields has the same name as a field of the nested structure itself. See the added test for an example.

Changing this doesn't break any of the existing tests.

pikanezi commented 2 years ago

thanks!