-
-
Notifications
You must be signed in to change notification settings - Fork 218
Reopen #573 #841
Description
Describe the bug
#573 should be reopened.
The required API behavior as the suggested "solution" is a clear violation of Go best practices, is needlessly restrictive, and is broken by design - types should be able to marshal whether they are used as a pointer or value on a field.
To Reproduce
(See #573)
Expected behavior
(See #573)
Screenshots
N/A
Version Variables
- Go version: 1.25.6
- go-yaml's Version: v1.19.2
Additional context
- bug: MarshalYAML does not get called #573 requires a value receiver if the containing struct field is a value and not a pointer, and vice versa.
- This means one cannot use both value fields and pointer fields for the same type, as you cannot define the same method name for the same type as a value receiver vs. pointer receiver. THIS IS BROKEN BEHAVIOR. I can think of no other library that has this quite frankly absolutely insane requirement/behavior.
Additionally:
- An
UnmarshalYAMLmethod must, by definition, be a pointer receiver (otherwise it cannot modify the value) - As stated before, this is not only broken design but also clearly violates Go guidelines:
Next is consistency. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used. See the section on mthod sets for details.
(emphasis added)
This violates Go best practices and is extremely anti-pattern, and is in direct conflict with expected behavior based on both other third-party Marshal* functionality and stdlib Marshal* functionality.