Commit e1b2d61c by Kyle Brandt Committed by GitHub

backend: null.Float NaN -> null for json marshal (#18284)

parent 54f3e873
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math"
"reflect" "reflect"
"strconv" "strconv"
) )
...@@ -99,7 +100,7 @@ func (f *Float) UnmarshalText(text []byte) error { ...@@ -99,7 +100,7 @@ func (f *Float) UnmarshalText(text []byte) error {
// MarshalJSON implements json.Marshaler. // MarshalJSON implements json.Marshaler.
// It will encode null if this Float is null. // It will encode null if this Float is null.
func (f Float) MarshalJSON() ([]byte, error) { func (f Float) MarshalJSON() ([]byte, error) {
if !f.Valid { if !f.Valid || math.IsNaN(f.Float64) {
return []byte(nullString), nil return []byte(nullString), nil
} }
return []byte(strconv.FormatFloat(f.Float64, 'f', -1, 64)), nil return []byte(strconv.FormatFloat(f.Float64, 'f', -1, 64)), nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment