// UnmarshalRole unmarshals role from JSON, sets defaults, and checks schema.
504046
func UnmarshalRole(data []byte, opts ...MarshalOption) (*RoleV3, error) {
	var h ResourceHeader
	err := json.Unmarshal(data, &h)
	if err != nil {
		h.Version = V2
	}

	cfg, err := collectOptions(opts)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	switch h.Version {
	case V2:
		var role RoleV2
		if err := utils.UnmarshalWithSchema(GetRoleSchema(V2, ""), &role, data); err != nil {
			return nil, trace.BadParameter(err.Error())
		}

		if err := role.CheckAndSetDefaults(); err != nil {
			return nil, trace.Wrap(err)
		}

		roleV3 := role.V3()
		roleV3.SetResourceID(cfg.ID)
		return roleV3, nil
	case V3:
		var role RoleV3
		if cfg.SkipValidation {
			if err := utils.FastUnmarshal(data, &role); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		} else {
			if err := utils.UnmarshalWithSchema(GetRoleSchema(V3, ""), &role, data); err != nil {
				return nil, trace.BadParameter(err.Error())
			}
		}

		if err := role.CheckAndSetDefaults(); err != nil {
			return nil, trace.Wrap(err)
		}

		if cfg.ID != 0 {
			role.SetResourceID(cfg.ID)
		}
		if !cfg.Expires.IsZero() {
			role.SetExpiry(cfg.Expires)
		}
		return &role, nil
	}

	return nil, trace.BadParameter("role version %q is not supported", h.Version)
}
1370378
func (s *Serializer) Unmarshal(data []byte, v interface{}) error {
	return json.Unmarshal(data, v)
}
188672
func (key *AppKey) Unmarshal(data []byte) error {
	*key = [16]byte{} // Reset the receiver
	return key.UnmarshalBinary(data)
}
688118
func (p *Partial) Unmarshal(v interface{}) error {
	if p == nil {
		return fmt.Errorf("Cannot unmarshal nil argument")
	}

	if err := json.Unmarshal(p.Raw, &v); err != nil {
		return fmt.Errorf("%s. Data: %s", err.Error(), string(p.Raw))
	}

	value := reflect.ValueOf(v)

	for _, spec := range p.CallbackSpecs {
		if err := setCallback(value, spec.Path, spec.Function.Caller.(functionReceived)); err != nil {
			return err
		}
	}

	return nil
}
403940
func (n *AppNonce) Unmarshal(data []byte) error {
	*n = [3]byte{} // Reset the receiver
	return n.UnmarshalBinary(data)
}
32700
func (b *PolicyBindings) UnmarshalJSON(data []byte) error {
	bindings := []roleBinding{}
	if err := json.Unmarshal(data, &bindings); err != nil {
		return err
	}
	newOne := make(PolicyBindings, len(bindings))
	for _, item := range bindings {
		members := make(membersSet, len(item.Members))
		for _, member := range item.Members {
			members[member] = struct{}{}
		}
		newOne[item.Role] = members
	}
	*b = newOne
	return nil
}
517153
func (l *IAMRolePolicyList) UnmarshalJSON(buf []byte) error {
	// Cloudformation allows a single object when a list of objects is expected
	item := IAMRolePolicy{}
	if err := json.Unmarshal(buf, &item); err == nil {
		*l = IAMRolePolicyList{item}
		return nil
	}
	list := []IAMRolePolicy{}
	err := json.Unmarshal(buf, &list)
	if err == nil {
		*l = IAMRolePolicyList(list)
		return nil
	}
	return err
}
351789
func (r *Redis) Unmarshal(key string, object interface{}) error {
	value, err := r.Get(key)
	if err == nil {
		err = json.Unmarshal([]byte(value), object)
	}
	return err
}
1234086
func (schema *Schema) Unmarshal(message []byte, s interface{}) error {
	v := reflect.ValueOf(s)
	vp := reflect.ValueOf(s)

	if v.Kind() == reflect.PtrTo(reflect.TypeOf(s)).Kind() {
		v = reflect.Indirect(v)
	}

	// Only structs are supported so return an empty result if the passed object
	// isn't a struct.
	if v.Kind() != reflect.Struct {
		return ErrUnsupportedType(v.Kind())
	}

	// If a pointer to a struct is passed, get the type of the dereferenced object.
	typ := reflect.TypeOf(s)
	if typ.Kind() == reflect.Ptr {
		typ = typ.Elem()
	}

	return populateStructFromSchema(schema.Definition, message, typ, v, vp)
}
404760
func (c *agencyConnection) Unmarshal(data driver.RawObject, result interface{}) error {
	c.mutex.RLock()
	defer c.mutex.RUnlock()

	if len(c.connections) == 0 {
		return driver.WithStack(fmt.Errorf("no connections"))
	}
	if err := c.connections[0].Unmarshal(data, result); err != nil {
		return driver.WithStack(err)
	}
	return nil
}
791296
func (l *S3BucketFilterRuleList) UnmarshalJSON(buf []byte) error {
	// Cloudformation allows a single object when a list of objects is expected
	item := S3BucketFilterRule{}
	if err := json.Unmarshal(buf, &item); err == nil {
		*l = S3BucketFilterRuleList{item}
		return nil
	}
	list := []S3BucketFilterRule{}
	err := json.Unmarshal(buf, &list)
	if err == nil {
		*l = S3BucketFilterRuleList(list)
		return nil
	}
	return err
}
825117
func (eui *AppEUI) Unmarshal(data []byte) error {
	*eui = [8]byte{} // Reset the receiver
	return eui.UnmarshalBinary(data)
}
58259
func (o *RAMRole) UnmarshalJSON(data []byte) error {
	var jsonName string
	if err := json.Unmarshal(data, &jsonName); err == nil {
		o.Name = &jsonName
		return nil
	}

	var r realRAMRole
	if err := json.Unmarshal(data, &r); err != nil {
		return err
	}
	*o = RAMRole(r)
	return nil
}
153533
func (n *DevNonce) Unmarshal(data []byte) error {
	*n = [2]byte{} // Reset the receiver
	return n.UnmarshalBinary(data)
}
576842
func (l *S3BucketServerSideEncryptionRuleList) UnmarshalJSON(buf []byte) error {
	// Cloudformation allows a single object when a list of objects is expected
	item := S3BucketServerSideEncryptionRule{}
	if err := json.Unmarshal(buf, &item); err == nil {
		*l = S3BucketServerSideEncryptionRuleList{item}
		return nil
	}
	list := []S3BucketServerSideEncryptionRule{}
	err := json.Unmarshal(buf, &list)
	if err == nil {
		*l = S3BucketServerSideEncryptionRuleList(list)
		return nil
	}
	return err
}
197142
func (key *NwkSKey) Unmarshal(data []byte) error {
	*key = [16]byte{} // Reset the receiver
	return key.UnmarshalBinary(data)
}
1339781
func JSONMarshalRules(rules api.Rules) string {
	b, err := json.MarshalIndent(rules, "", "  ")
	if err != nil {
		return err.Error()
	}
	return string(b)
}