func (this *ScopeExpressionTemplate) UnmarshalJSON(data []byte) error {
	if this == nil {
		return errors.New("ScopeExpressionTemplate: UnmarshalJSON on nil pointer")
	}
	this.RawMessage = append((this.RawMessage)[0:0], data...)
	var tempObj interface{}
	err := json.Unmarshal(this.RawMessage, &tempObj)
	if err != nil {
		panic("Internal error: " + err.Error())
	}
	switch t := tempObj.(type) {
	case string:
		this.Type = "RequiredScope"
		this.RequiredScope = new(RequiredScope)
		*(this.RequiredScope) = RequiredScope(t)
	case map[string]interface{}:
		j, err := json.Marshal(t)
		if err != nil {
			panic("Internal error: " + err.Error())
		}
		if _, exists := t["AnyOf"]; exists {
			this.Type = "AnyOf"
			this.AnyOf = new(Disjunction)
			err = json.Unmarshal(j, this.AnyOf)
		}
		if _, exists := t["AllOf"]; exists {
			this.Type = "AllOf"
			this.AllOf = new(Conjunction)
			err = json.Unmarshal(j, this.AllOf)
		}
		if _, exists := t["if"]; exists {
			this.Type = "IfThen"
			this.IfThen = new(Conditional)
			err = json.Unmarshal(j, this.IfThen)
		}
		if _, exists := t["for"]; exists {
			this.Type = "ForEachIn"
			this.ForEachIn = new(ForAll)
			err = json.Unmarshal(j, this.ForEachIn)
		}
		if err != nil {
			panic("Internal error: " + err.Error())
		}
	// for old style scopesets [][]string (normal disjunctive form)
	case []interface{}:
		this.Type = "AnyOf"
		this.AnyOf = &Disjunction{
			AnyOf: make([]ScopeExpressionTemplate, len(t), len(t)),
		}
		for i, j := range t {
			allOf := j.([]interface{})
			this.AnyOf.AnyOf[i] = ScopeExpressionTemplate{
				Type: "AllOf",
				AllOf: &Conjunction{
					AllOf: make([]ScopeExpressionTemplate, len(allOf), len(allOf)),
				},
			}
			for k, l := range allOf {
				rs := RequiredScope(l.(string))
				this.AnyOf.AnyOf[i].AllOf.AllOf[k] = ScopeExpressionTemplate{
					Type:          "RequiredScope",
					RequiredScope: &rs,
				}
			}
		}
	default:
		panic(fmt.Sprintf("Internal error: unrecognised type %T for json: %v", t, string(data)))
	}
	return nil
}
func (this *ScopeExpressionTemplate) UnmarshalJSON(data []byte) error {
	if this == nil {
		return errors.New("ScopeExpressionTemplate: UnmarshalJSON on nil pointer")
	}
	this.RawMessage = append((this.RawMessage)[0:0], data...)
	var tempObj interface{}
	err := json.Unmarshal(this.RawMessage, &tempObj)
	if err != nil {
		panic("Internal error: " + err.Error())
	}
	switch t := tempObj.(type) {
	case string:
		this.Type = "RequiredScope"
		this.RequiredScope = new(RequiredScope)
		*(this.RequiredScope) = RequiredScope(t)
	case map[string]interface{}:
		j, err := json.Marshal(t)
		if err != nil {
			panic("Internal error: " + err.Error())
		}
		if _, exists := t["AnyOf"]; exists {
			this.Type = "AnyOf"
			this.AnyOf = new(Disjunction)
			err = json.Unmarshal(j, this.AnyOf)
		}
		if _, exists := t["AllOf"]; exists {
			this.Type = "AllOf"
			this.AllOf = new(Conjunction)
			err = json.Unmarshal(j, this.AllOf)
		}
		if _, exists := t["if"]; exists {
			this.Type = "IfThen"
			this.IfThen = new(Conditional)
			err = json.Unmarshal(j, this.IfThen)
		}
		if _, exists := t["for"]; exists {
			this.Type = "ForEachIn"
			this.ForEachIn = new(ForAll)
			err = json.Unmarshal(j, this.ForEachIn)
		}
		if err != nil {
			panic("Internal error: " + err.Error())
		}
	// for old style scopesets [][]string (normal disjunctive form)
	case []interface{}:
		this.Type = "AnyOf"
		this.AnyOf = &Disjunction{
			AnyOf: make([]ScopeExpressionTemplate, len(t), len(t)),
		}
		for i, j := range t {
			allOf := j.([]interface{})
			this.AnyOf.AnyOf[i] = ScopeExpressionTemplate{
				Type: "AllOf",
				AllOf: &Conjunction{
					AllOf: make([]ScopeExpressionTemplate, len(allOf), len(allOf)),
				},
			}
			for k, l := range allOf {
				rs := RequiredScope(l.(string))
				this.AnyOf.AnyOf[i].AllOf.AllOf[k] = ScopeExpressionTemplate{
					Type:          "RequiredScope",
					RequiredScope: &rs,
				}
			}
		}
	default:
		panic(fmt.Sprintf("Internal error: unrecognised type %T for json: %v", t, string(data)))
	}
	return nil
}
// UnmarshalJSON identifies the data structure at runtime, and unmarshals in
// the appropriate type