I have a struct which contains an other struct as value object.
type User struct {
Name string `json:"name"``
Email valueobject.Email `json:"email"`
}
The valueobject.Email
looks like this:
type Email struct {
value string
}
func (e *Email) Value() string {
return e.Value
}
I want the value object as an immutable object, there is also a "factory" method in this is not necessary for my problem.
Now I want to return the User struct as json and therefor I use
response := map[string]interface{}{"user": User}
json.NewEncoder(w).Encode(response)
The result is:
{
"user": {
"name": "John Doe",
"email": {
"Email: "johndoe@example.com"
}
}
}
But I want something link this:
{
"user": {
"name": "John Doe",
"email": "johndoe@example.com"
}
}