/*
UnmarshalJSON allows us to manually decode a the resource linkage via the
json.Unmarshaler interface.
*/
192140
func (rl *ResourceLinkage) UnmarshalJSON(data []byte) error {
	// Create a sub-type here so when we call Unmarshal below, we don't recursively
	// call this function over and over
	type UnmarshalLinkage ResourceLinkage

	// if our "List" is a single object, modify the JSON to make it into a list
	// by wrapping with "[ ]"
	if data[0] == '{' {
		data = []byte(fmt.Sprintf("[%s]", data))
	}

	newLinkage := UnmarshalLinkage{}

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

	convertedLinkage := ResourceLinkage(newLinkage)
	*rl = convertedLinkage

	return nil
}
502521
func (x *Communication) UnmarshalJSON(data []byte) (err error) {
	x2 := communication{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = Communication(x2)
		return x.checkResourceType()
	}
	return
}
847111
func (x *ProcedureRequest) UnmarshalJSON(data []byte) (err error) {
	x2 := procedureRequest{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = ProcedureRequest(x2)
		return x.checkResourceType()
	}
	return
}
245918
func (self *Resource) UnmarshalJSON(b []byte) error {
	var m rawResource
	err := json.Unmarshal(b, &m)
	if err == nil {
		o := Resource(m)
		*self = *((&o).Init())
		err = self.Validate()
	}
	return err
}
1210096
func (x *SupplyRequest) UnmarshalJSON(data []byte) (err error) {
	x2 := supplyRequest{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = SupplyRequest(x2)
		return x.checkResourceType()
	}
	return
}
398164
func (c *FileLink) UnmarshalJSON(data []byte) error {
	if id, ok := ParseID(data); ok {
		c.ID = id
		return nil
	}

	type fileLink FileLink
	var v fileLink
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}

	*c = FileLink(v)
	return nil
}
56618
func (x *ReferralRequest) UnmarshalJSON(data []byte) (err error) {
	x2 := referralRequest{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = ReferralRequest(x2)
		return x.checkResourceType()
	}
	return
}
1044571
func (self *ResourceAuth) UnmarshalJSON(b []byte) error {
	var m rawResourceAuth
	err := json.Unmarshal(b, &m)
	if err == nil {
		o := ResourceAuth(m)
		*self = o
		err = self.Validate()
	}
	return err
}
919185
func (x *Bundle) UnmarshalJSON(data []byte) (err error) {
	x2 := bundle{}
	if err = json.Unmarshal(data, &x2); err == nil {
		*x = Bundle(x2)
		return x.checkResourceType()
	}
	return
}
1236674
func (id *ResourceID) UnmarshalJSON(data []byte) (err error) {
	var str string
	if err := json.Unmarshal(data, &str); err != nil {
		return err
	}
	if string(str) == "" {
		// Sadly needed as it's possible to construct an empty ResourceID literal
		*id = ResourceID{}
		return nil
	}
	*id, err = ParseResourceID(string(str))
	return err
}
945522
func (x *BodySite) UnmarshalJSON(data []byte) (err error) {
	x2 := bodySite{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = BodySite(x2)
		return x.checkResourceType()
	}
	return
}
429494
func (x *Person) UnmarshalJSON(data []byte) (err error) {
	x2 := person{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = Person(x2)
		return x.checkResourceType()
	}
	return
}
548492
func (u *Unstructured) UnmarshalJSON(b []byte) error {
	_, _, err := UnstructuredJSONScheme.Decode(b, nil, u)
	return err
}
592062
func (al *HALLinks) UnmarshalJSON(j []byte) (err error) {
	var d linkField
	if err = json.Unmarshal(j, &d); err != nil {
		return
	}

	var u *url.URL
	for linkName, value := range d {
		if u, err = url.Parse(value["href"]); err != nil {
			break
		}
		al.Add(&HALLink{
			Name: linkName,
			URL:  u,
		})
	}
	return
}
488706
func (o *ResourceHolder) UnmarshalJSON(data []byte) error {
	var jsonName string
	err := json.Unmarshal(data, &jsonName)
	if err != nil {
		return err
	}
	o.Name = jsonName
	return nil
}
61647
func (x *PaymentNotice) UnmarshalJSON(data []byte) (err error) {
	x2 := paymentNotice{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = PaymentNotice(x2)
		return x.checkResourceType()
	}
	return
}
228089
func (x *DeviceComponent) UnmarshalJSON(data []byte) (err error) {
	x2 := deviceComponent{}
	if err = json.Unmarshal(data, &x2); err == nil {
		if x2.Contained != nil {
			for i := range x2.Contained {
				x2.Contained[i] = MapToResource(x2.Contained[i], true)
			}
		}
		*x = DeviceComponent(x2)
		return x.checkResourceType()
	}
	return
}