MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / UnmarshalJSON

Method UnmarshalJSON

internal/models/view.go:82–100  ·  view source on GitHub ↗

UnmarshalJSON for ViewUpdate accepts `config` either as the canonical JSON-encoded string shape OR as the natural nested object shape any reasonable HTTP client would send. Mirrors ItemUpdate.UnmarshalJSON; the struct field stays `*string` and downstream consumers (store writes, web/CLI) are unchang

(data []byte)

Source from the content-addressed store, hash-verified

80// at views.go:152 only sees empty-string-or-valid-object input; the
81// "is it a JSON object" assertion sits at the handler boundary.
82func (u *ViewUpdate) UnmarshalJSON(data []byte) error {
83 type alias ViewUpdate
84 aux := struct {
85 Config json.RawMessage `json:"config,omitempty"`
86 *alias
87 }{alias: (*alias)(u)}
88
89 if err := json.Unmarshal(data, &aux); err != nil {
90 return err
91 }
92
93 configStr, err := flexJSONToString(aux.Config, '{', ErrInvalidConfigType)
94 if err != nil {
95 return err
96 }
97 u.Config = configStr
98
99 return nil
100}

Callers

nothing calls this directly

Calls 1

flexJSONToStringFunction · 0.85

Tested by

no test coverage detected