Preserve text marshalers in absent-facet conversion

Review of the nil fast path identified named nil collections that implement encoding.TextMarshaler rather than json.Marshaler. Keep the parent representation for both interfaces and retain matching byte-level controls.

Contract-Neutral: Conversion work only; retain the exact existing JSON and text-marshaler representations and all broadcast fields and freshness boundaries.
Change-source: pulse-maintainer
This commit is contained in:
pulse-triage[bot]
2026-10-05 14:18:18 +01:00
parent eb26fbba05
commit 8310e8341e
2 changed files with 14 additions and 1 deletions
@@ -22,6 +22,14 @@ type projectionNilMap map[string]string
func (projectionNilMap) MarshalJSON() ([]byte, error) { return []byte(`{"custom":true}`), nil }
type projectionNilTextSlice []string
func (projectionNilTextSlice) MarshalText() ([]byte, error) { return []byte("custom-text"), nil }
type projectionNilTextMap map[string]string
func (projectionNilTextMap) MarshalText() ([]byte, error) { return []byte("custom-text"), nil }
type projectionInvalidJSON struct{}
func (projectionInvalidJSON) MarshalJSON() ([]byte, error) { return []byte(`{broken`), nil }
@@ -53,6 +61,8 @@ func TestBroadcastRawJSONPreservesAbsentEmptyAndFailureSemantics(t *testing.T) {
{"empty-slice", []string{}}, {"empty-map", map[string]string{}},
{"named-nil-slice-marshaler", projectionNilSlice(nil)},
{"named-nil-map-marshaler", projectionNilMap(nil)},
{"named-nil-slice-text-marshaler", projectionNilTextSlice(nil)},
{"named-nil-map-text-marshaler", projectionNilTextMap(nil)},
{"nil-pointer-marshaler", (*projectionNilSlice)(nil)},
{"invalid-json", projectionInvalidJSON{}}, {"encode-failure", projectionFailedJSON{}},
{"invalid-float", math.NaN()}, {"raw-null", json.RawMessage(`null`)},
+4 -1
View File
@@ -3,6 +3,7 @@ package monitoring
import (
"context"
"crypto/sha256"
"encoding"
"encoding/hex"
"encoding/json"
stderrors "errors"
@@ -6654,7 +6655,9 @@ func monitorRawJSON(value interface{}) json.RawMessage {
case reflect.Slice, reflect.Map:
if v.IsNil() {
if _, custom := value.(json.Marshaler); !custom {
return nil
if _, customText := value.(encoding.TextMarshaler); !customText {
return nil
}
}
}
}