Fix to correctly deserialize JSON null value for Route.CPUs (#909)

This commit is contained in:
Owen Strain
2018-03-29 16:38:51 -07:00
committed by GitHub
parent 4b3cd28cb9
commit f03d1c294a

View File

@@ -147,6 +147,12 @@ func (c MilliCPUs) String() string {
func (c *MilliCPUs) UnmarshalJSON(data []byte) error {
outer := bytes.TrimSpace(data)
if bytes.Equal(outer, []byte("null")) {
*c = MilliCPUs(0)
return nil
}
if !bytes.HasSuffix(outer, []byte("\"")) || !bytes.HasPrefix(outer, []byte("\"")) {
return ErrInvalidJSON
}