hashicorp / go-multierror

A Go (golang) package for representing a list of errors as a single error.
Mozilla Public License 2.0
2.3k stars 123 forks source link

Added MarshalJSON function for Error #4

Closed malpiatko closed 7 years ago

malpiatko commented 8 years ago

Added a simple MarshalJSON to enable marshalling of the error.

mitchellh commented 8 years ago

If we're going to Marshal it we should probably have a function to Unmarshal as well.

malpiatko commented 8 years ago

Hey, I have changed the code significantly by adding json tags to field, this is almost equivalent to the MarshalJSON function except now we will have marshalled error like this: { errors: <array of errors> }

Instead of: `{

}` You asked me to write an Unmarshal function, however I don't think it's possible. Since, Error consists of array of object with error interface, which does not implement UnmarshalJSON, the unmarshaling will not be possible. On the other hand for Marshaling, in most cases the array will be marshalled to `{errors: [{},{},....]}` However, if the errors in the array are of type which implement MarshalJSON that will be used to represent them.