Closed Techno-Fox closed 2 years ago
Hi! could you please provide a simple reproducer to fully understand the flow?
package main
import (
"encoding/json"
"log"
"github.com/jaypipes/ghw"
)
func main() {
blocks, err := ghw.Block(ghw.WithDisableWarnings())
if err != nil {
log.Fatal(err)
}
data, err := json.Marshal(blocks)
if err != nil {
log.Fatal(err)
}
var bi *ghw.BlockInfo
err = json.Unmarshal(data, &bi)
if err != nil {
log.Fatal(err)
}
}
thanks @Techno-Fox ! working on a fix
I was trying to marshal and unmarshal data, but then this comes up. I believe it's because DriveType is an int, while the marshaled version is a string, because of the MarshalJSON function converting it to a string.
Proposal: Add an UnmarshalJSON function to types that are converted from the original. To be converted back their original type for unmarshaling.
Please correct me if I'm wrong!