MCPcopy Create free account
hub / github.com/git-bug/git-bug / UnmarshalJSON

Function UnmarshalJSON

entities/identity/common.go:13–28  ·  view source on GitHub ↗

Custom unmarshaling function to allow package user to delegate the decoding of an Identity and distinguish between an Identity and a Bare. If the given message has a "id" field, it's considered being a proper Identity.

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

11//
12// If the given message has a "id" field, it's considered being a proper Identity.
13func UnmarshalJSON(raw json.RawMessage) (Interface, error) {
14 aux := &IdentityStub{}
15
16 // First try to decode and load as a normal Identity
17 err := json.Unmarshal(raw, &aux)
18 if err == nil && aux.Id() != "" {
19 return aux, nil
20 }
21
22 // abort if we have an error other than the wrong type
23 if _, ok := err.(*json.UnmarshalTypeError); err != nil && !ok {
24 return nil, err
25 }
26
27 return nil, fmt.Errorf("unknown identity type")
28}

Callers 1

TestJSONFunction · 0.85

Calls 2

IdMethod · 0.95
ErrorfMethod · 0.80

Tested by 1

TestJSONFunction · 0.68