MCPcopy Create free account
hub / github.com/cogentcore/core / MarshalJSON

Method MarshalJSON

tree/json.go:23–35  ·  view source on GitHub ↗

MarshalJSON marshals the node by injecting the [Node.NodeType] as a nodeType field and the [NodeBase.NumChildren] as a numChildren field at the start of the standard JSON encoding output.

()

Source from the content-addressed store, hash-verified

21// field and the [NodeBase.NumChildren] as a numChildren field at the start of
22// the standard JSON encoding output.
23func (n *NodeBase) MarshalJSON() ([]byte, error) {
24 // the non pointer value does not implement MarshalJSON, so it will not result in infinite recursion
25 b, err := json.Marshal(reflectx.Underlying(reflect.ValueOf(n.This)).Interface())
26 if err != nil {
27 return b, err
28 }
29 data := `"nodeType":"` + n.NodeType().Name + `",`
30 if n.NumChildren() > 0 {
31 data += `"numChildren":` + strconv.Itoa(n.NumChildren()) + ","
32 }
33 b = slices.Insert(b, 1, []byte(data)...)
34 return b, nil
35}
36
37// unmarshalTypeCache is a cache of [reflect.Type] values used
38// for unmarshalling in [NodeBase.UnmarshalJSON]. This cache has

Callers 2

lockFileMethod · 0.45
saveLastSaveMethod · 0.45

Calls 4

NodeTypeMethod · 0.95
NumChildrenMethod · 0.95
UnderlyingFunction · 0.92
InsertMethod · 0.45

Tested by

no test coverage detected