mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-23 20:25:56 +00:00
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:
@@ -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`)},
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user