func (x *DeviceMetric) UnmarshalJSON(data []byte) (err error) {
	x2 := deviceMetric{}
	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 = DeviceMetric(x2)
		return x.checkResourceType()
	}
	return
}
Custom unmarshaller to properly unmarshal embedded resources (represented as interface{})
package models
import (
	"encoding/json"
	"errors"
	"fmt"
)
type DeviceMetric struct {
	DomainResource    `bson:",inline"`
	Type              *CodeableConcept                   `bson:"type,omitempty" json:"type,omitempty"`
	Identifier        *Identifier                        `bson:"identifier,omitempty" json:"identifier,omitempty"`
	Unit              *CodeableConcept                   `bson:"unit,omitempty" json:"unit,omitempty"`
	Source            *Reference                         `bson:"source,omitempty" json:"source,omitempty"`
	Parent            *Reference                         `bson:"parent,omitempty" json:"parent,omitempty"`
	OperationalStatus string                             `bson:"operationalStatus,omitempty" json:"operationalStatus,omitempty"`
	Color             string                             `bson:"color,omitempty" json:"color,omitempty"`
	Category          string                             `bson:"category,omitempty" json:"category,omitempty"`
	MeasurementPeriod *Timing                            `bson:"measurementPeriod,omitempty" json:"measurementPeriod,omitempty"`
	Calibration       []DeviceMetricCalibrationComponent `bson:"calibration,omitempty" json:"calibration,omitempty"`
}
func (resource *DeviceMetric) MarshalJSON() ([]byte, error) {
	resource.ResourceType = "DeviceMetric"
	return json.Marshal(*resource)
}
func (x *DeviceMetric) GetBSON() (interface{}, error) {
	x.ResourceType = "DeviceMetric"
	return *x, nil
}
type deviceMetric DeviceMetric