Exemplo n.º 1
0
/*
Unmarshals byte array.
*/
func UnmarshalUnsetTerm(body []byte) (*algebra.UnsetTerm, error) {
	var _unmarshalled struct {
		Path string          `json:"path"`
		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("UnmarshalUnsetTerm: cannot resolve path expression from %s",
			_unmarshalled.Path)
	}

	var updateFor *algebra.UpdateFor
	if len(_unmarshalled.For) > 0 {
		updateFor, err = UnmarshalUpdateFor(_unmarshalled.For)
		if err != nil {
			return nil, err
		}
	}

	return algebra.NewUnsetTerm(path, updateFor), nil
}
Exemplo n.º 2
0
/*
Unmarshals byte array.
*/
func UnmarshalUnsetTerms(body []byte) (algebra.UnsetTerms, error) {
	var _unmarshalled []struct {
		Path string          `json:"path"`
		For  json.RawMessage `json:"path_for"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return nil, err
	}

	terms := make(algebra.UnsetTerms, 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("UnmarshalUnsetTerms: cannot resolve path expression from %s",
				term.Path)
		}

		var updateFor *algebra.UpdateFor
		if len(term.For) > 0 {
			updateFor, err = UnmarshalUpdateFor(term.For)
			if err != nil {
				return nil, err
			}
		}

		terms[i] = algebra.NewUnsetTerm(path, updateFor)
	}

	return terms, nil
}
Exemplo n.º 3
0
func (this *Unset) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_          string `json:"#operator"`
		UnsetTerms []struct {
			Path string `json:"path"`
			Expr string `json:"expr"`
		} `json:"unset_terms"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	terms := make([]*algebra.UnsetTerm, len(_unmarshalled.UnsetTerms))
	for i, UnsetTerm := range _unmarshalled.UnsetTerms {
		path_expr, err := parser.Parse(UnsetTerm.Path)
		if err != nil {
			return err
		}

		path, is_path := path_expr.(expression.Path)
		if !is_path {
			return fmt.Errorf("Unset.UnmarshalJSON: cannot resolve path expression from %s", UnsetTerm.Path)
		}

		// is expr needed in Unset?
		_, err = parser.Parse(UnsetTerm.Expr)
		if err != nil {
			return err
		}

		terms[i] = algebra.NewUnsetTerm(path, nil)
	}
	this.node = algebra.NewUnset(terms)
	return nil
}