@@ -54,8 +54,14 @@ type OpenTelemetryCollector struct {
54
54
// Hub exists to allow for conversion.
55
55
func (* OpenTelemetryCollector ) Hub () {}
56
56
57
+ // MarshalJSON marshalls the OpenTelemetry Collector to JSON.
57
58
func (o * OpenTelemetryCollector ) MarshalJSON () ([]byte , error ) {
59
+ // When you marshal a struct that embeds itself or a type that directly or indirectly refers back to itself,
60
+ // Go's JSON marshaling can lead to infinite recursion. To avoid this, we create an alias of the struct
61
+ // (Config), so Go no longer considers it the same type.
62
+ // This allows you to embed the struct safely within itself without triggering that infinite loop.
58
63
type Alias OpenTelemetryCollector
64
+ // Ensure we call the custom marshaller for Spec
59
65
specJSON , err := json .Marshal (& o .Spec )
60
66
if err != nil {
61
67
return nil , err
@@ -160,8 +166,14 @@ type OpenTelemetryCollectorSpec struct {
160
166
DeploymentUpdateStrategy appsv1.DeploymentStrategy `json:"deploymentUpdateStrategy,omitempty"`
161
167
}
162
168
169
+ // MarshalJSON marshalls the OpenTelemetryCollectorSpec field.
163
170
func (s * OpenTelemetryCollectorSpec ) MarshalJSON () ([]byte , error ) {
171
+ // When you marshal a struct that embeds itself or a type that directly or indirectly refers back to itself,
172
+ // Go's JSON marshaling can lead to infinite recursion. To avoid this, we create an alias of the struct
173
+ // (Config), so Go no longer considers it the same type.
174
+ // This allows you to embed the struct safely within itself without triggering that infinite loop.
164
175
type Alias OpenTelemetryCollectorSpec
176
+ // Ensure we call the custom marshaller for Config
165
177
configJSON , err := json .Marshal (s .Config )
166
178
if err != nil {
167
179
return nil , err
0 commit comments