I wan´t to unmarshal json to an exported struct from other package but I does not work propertly
package anyPackage
type DataStruct struct{
Size int `json:"size"`
Material string `json:"material"`
Date time.Time
}
package main
import (
"fmt"
"log"
"encoding/json"
"customPackage/anyPackage"
)
type NewStruct struct{
Name string `json:"name"`
Code int `json:"code"`
ExtraData anyPackage.DataStruct
}
func main(){
blob := `{ "name":"John", "code":12546, "material":"wood","size":456 }`
var aux NewStruct
if err := json.Unmarshal([]byte(blob), &aux); err != nil {
log.Fatal(err)
}
fmt.Printf("%+v", aux)
}
In that case, name and code are correctly unmarshal, but material and size don´t, they are empty