/* Unmarshals byte array. */ func UnmarshalSetTerms(body []byte) (algebra.SetTerms, error) { var _unmarshalled []struct { Path string `json:"path"` Value string `json:"value"` For json.RawMessage `json:"path_for"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } terms := make(algebra.SetTerms, len(_unmarshalled)) for i, term := range _unmarshalled { path_expr, err := parser.Parse(term.Path) if err != nil { return nil, err } path, is_path := path_expr.(expression.Path) if !is_path { return nil, fmt.Errorf("UnmarshalSetTerms: cannot resolve path expression from %s", term.Path) } value, err := parser.Parse(term.Value) if err != nil { return nil, err } var updateFor *algebra.UpdateFor if len(term.For) > 0 { updateFor, err = UnmarshalUpdateFor(term.For) if err != nil { return nil, err } } terms[i] = algebra.NewSetTerm(path, value, updateFor) } return terms, nil }
/* Unmarshals byte array. */ func UnmarshalSetTerm(body []byte) (*algebra.SetTerm, error) { var _unmarshalled struct { Path string `json:"path"` Value string `json:"value"` For json.RawMessage `json:"path_for"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } path_expr, err := parser.Parse(_unmarshalled.Path) if err != nil { return nil, err } path, is_path := path_expr.(expression.Path) if !is_path { return nil, fmt.Errorf("UnmarshalSetTerm: cannot resolve path expression from %s", _unmarshalled.Path) } value, err := parser.Parse(_unmarshalled.Value) if err != nil { return nil, err } var updateFor *algebra.UpdateFor if len(_unmarshalled.For) > 0 { updateFor, err = UnmarshalUpdateFor(_unmarshalled.For) if err != nil { return nil, err } } return algebra.NewSetTerm(path, value, updateFor), nil }
func (this *Set) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` SetTerms []struct { Path string `json:"path"` Expr string `json:"expr"` } `json:"set_terms"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } terms := make([]*algebra.SetTerm, len(_unmarshalled.SetTerms)) for i, SetTerm := range _unmarshalled.SetTerms { path_expr, err := parser.Parse(SetTerm.Path) if err != nil { return err } path, is_path := path_expr.(expression.Path) if !is_path { return fmt.Errorf("Set.UnmarshalJSON: cannot resolve path expression from %s", SetTerm.Path) } expr, err := parser.Parse(SetTerm.Expr) if err != nil { return err } terms[i] = algebra.NewSetTerm(path, expr, nil) } this.node = algebra.NewSet(terms) return nil }