func (u *User) MarshalJSON() ([]byte, error) {
	if err := u.Validate(); err != nil {
		return nil, err
	}
	doc := struct {
		userAlias
		ID        string     `json:"_id"`
		Type      string     `json:"type"`
		Roles     []string   `json:"roles"`
		LastLogin *time.Time `json:"lastLogin,omitempty"`
	}{
		ID:        u.ID(),
		Type:      "user",
		userAlias: userAlias(*u),
	}
	if !u.LastLogin.IsZero() {
		doc.LastLogin = &u.LastLogin
	}
	if len(u.Roles) == 0 {
		// To ensure non-`null` value
		doc.Roles = []string{}
	} else {
		doc.Roles = u.Roles
	}
	return json.Marshal(doc)
}
// MarshalJSON implements the json.Marshaler interface for the User type.
MarshalJSON implements the json.Marshaler interface for the User type.
// MarshalJSON implements the json . Marshaler interface for the User type .
func (u *User) MarshalJSON() ([]byte, error) {
	if err := u.Validate(); err != nil {
		return nil, err
	}
	doc := struct {
		userAlias
		ID        string     `json:"_id"`
		Type      string     `json:"type"`
		Roles     []string   `json:"roles"`
		LastLogin *time.Time `json:"lastLogin,omitempty"`
	}{
		ID:        u.ID(),
		Type:      "user",
		userAlias: userAlias(*u),
	}
	if !u.LastLogin.IsZero() {
		doc.LastLogin = &u.LastLogin
	}
	if len(u.Roles) == 0 {
		doc.Roles = []string{}
	} else {
		doc.Roles = u.Roles
	}
	return json.Marshal(doc)
}
func ( u * User ) MarshalJSON ( ) ( [ ] byte , error ) { if err := u . Validate ( ) ; err != nil { return nil , err } doc := struct { userAlias ID string `json:"_id"` Type string `json:"type"` Roles [ ] string `json:"roles"` LastLogin * time . Time `json:"lastLogin,omitempty"` } { ID : u . ID ( ) , Type : " " , userAlias : userAlias ( * u ) , } if ! u . LastLogin . IsZero ( ) { doc . LastLogin = & u . LastLogin } if len ( u . Roles ) == 0 { doc . Roles = [ ] string { } } else { doc . Roles = u . Roles } return json . Marshal ( doc ) }
MarshalJSON implements the json.Marshaler interface for the User type.
MarshalJSON implements the json . Marshaler interface for the User type .
// To ensure non-`null` value