pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.72k stars 209 forks source link

Fix UnmarshalTOML is not called when its underlying type is an array #870

Open ImSingee opened 1 year ago

ImSingee commented 1 year ago

This PR is for v1.

This resolves the issue where, if a type implements toml.Unmarshaler but it has an array as its underlying type, the UnmarshalTOML method won't be triggered.

pelletier commented 1 year ago

Hi! Thank you for the patch! However v1 is not supported anymore and will not receive any update. Consider using go-toml v2 instead.

ImSingee commented 1 year ago

@pelletier Thanks for yor reminder. You can close this PR at your opinion.

I’m not using v2 (in fact, I just downgraded to v1 today) because and only because of the lack of missing toml.Unmarshaler interface.

Though there’s TextUnmarshaler, but it can only handle string fields. However, I want to (and need to) do more for historical reasons. The case is just that we have a field that needs to accept both a string and a string array. But in v2, there’s no way to implement it.

Is it possible to re-add the toml.Unmarshaler interface? It will do increase flexibility. And if you accept the feature, I can submit a PR to implement that.

pelletier commented 1 year ago

Makes sense. I'd be happy to see a good patch to implement toml.Unmarshaler for v2! I think it would also help others (https://github.com/pelletier/go-toml/issues/857).

ImSingee commented 1 year ago

@pelletier 👀 Okay, I will try to implement it!

pelletier commented 1 year ago

@ImSingee created https://github.com/pelletier/go-toml/issues/873 with some thoughts on the topic, hopefully it's helpful!