Closed Woody1193 closed 2 years ago
If I declare a struct like this:
type Option struct { Additional []*Additional Key string Value string } type Additional struct { Type string Value int }
and then I marshal an object of this type:
data = []*Option{ { Key: "test", Value: "test" } } file, _ := os.Create("test.csv") innerWriter := csv.NewWriter(file) innerWriter.Comma = '|' csvWriter := gocsv.NewSafeCSVWriter(innerWriter) if err := gocsv.MarshalCSV(data, csvWriter); err != nil { panic(err) }
This will produce the following output:
Additional|Key|Value |test|test
However, attempting to unmarshal this data using the following code:
file, _ := os.Open("test.csv") var data []*Option innerReader := csv.NewReader(file) innerReader.Comma = '|' if err := gocsv.UnmarshalCSV(innerReader, &data); err != nil { panic(err) }
I get the following error:
record on line 0; parse error on line 2, column 1: unexpected end of JSON input
It seems to me that the unmarshaller is not correctly determining that an empty column equates to an empty list in the case of a list of structs.
This issue has been addressed. Closing.
If I declare a struct like this:
and then I marshal an object of this type:
This will produce the following output:
However, attempting to unmarshal this data using the following code:
I get the following error:
It seems to me that the unmarshaller is not correctly determining that an empty column equates to an empty list in the case of a list of structs.