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

Method UnmarshalJSON

internal/models/collection.go:112–130  ·  view source on GitHub ↗

UnmarshalJSON for CollectionCreate accepts `settings` either as the canonical JSON-encoded string shape (matches models.Collection.Settings storage) OR as the natural nested object shape any reasonable HTTP client would send. Mirrors ItemCreate.UnmarshalJSON; see flexJSONToString in item.go for the

(data []byte)

Source from the content-addressed store, hash-verified

110// client would send. Mirrors ItemCreate.UnmarshalJSON; see
111// flexJSONToString in item.go for the shape contract.
112func (c *CollectionCreate) UnmarshalJSON(data []byte) error {
113 type alias CollectionCreate
114 aux := struct {
115 Settings json.RawMessage `json:"settings,omitempty"`
116 *alias
117 }{alias: (*alias)(c)}
118
119 if err := json.Unmarshal(data, &aux); err != nil {
120 return err
121 }
122
123 if settingsStr, err := flexJSONToString(aux.Settings, '{', ErrInvalidSettingsType); err != nil {
124 return err
125 } else if settingsStr != nil {
126 c.Settings = *settingsStr
127 }
128
129 return nil
130}
131
132// UnmarshalJSON for CollectionUpdate accepts `settings` either as the
133// canonical JSON-encoded string shape OR as the natural nested object

Callers

nothing calls this directly

Calls 1

flexJSONToStringFunction · 0.85

Tested by

no test coverage detected