Exemplo n.º 1
0
func (this *Unset) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_          string          `json:"#operator"`
		UnsetTerms json.RawMessage `json:"unset_terms"`
	}

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

	terms, err := unmarshal.UnmarshalUnsetTerms(_unmarshalled.UnsetTerms)
	if err != nil {
		return err
	}

	this.node = algebra.NewUnset(terms)
	return nil
}
Exemplo n.º 2
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
}