Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildJSONUnmarshaler ¶
BuildJSONUnmarshaler generates a custom implementation of the Unmarshaler type for the type of the provided struct. The preferred way to use BuildJSONUnmarshaler is to create a package-level variable and assign it in init with a nil instance of the type:
type Sample struct { FirstName *string LastName *string Age *int Inner *struct { Address string } Pet string Company string `json:"company"` modified []string } var sampleUnmarshaler modtracker.Unmarshaler func init() { var err error sampleUnmarshaler, err = modtracker.BuildJSONUnmarshaler((*Sample)(nil)) if err != nil { panic(err) } } func (s *Sample) UnmarshalJSON(data []byte) error { modified, err := sampleUnmarshaler(data, s) if err != nil { return err } s.modified = modified return nil }
func UnmarshalJSON ¶
UnmarshalJSON provides the default implementation of the Unmarshaler type. It will rediscover the fields in the structure each time it is called; to improve performance, use BuildJSONUnmarshaler to create an Unmarshaler instance with the struct fields pre-calculated.
Types ¶
type Modifiable ¶
type Modifiable interface {
GetModified() []string
}
Modifiable is implemented by struct types that contain a list of their fields that were populated from JSON. If a value for a field, even null, was provided in the JSON, the name of the field appears in the slice of strings.
type Unmarshaler ¶
An Unmarshaler takes in JSON in the first parameter, a pointer to a struct in the second parameter, populates the struct with the JSON and returns the modified fields as a slice of strings. In case of error, the struct might be partially populated. If there is an error, the modified field slice will be nil.