Beispiel #1
0
func (this *Set) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_        string          `json:"#operator"`
		SetTerms json.RawMessage `json:"set_terms"`
	}

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

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

	this.node = algebra.NewSet(terms)
	return nil
}
Beispiel #2
0
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
}