Si conoce la estructura de su BSON, puede crear un tipo personalizado que implemente json.Marshaler
y json.Unmarshaler
interfaces y maneja NaN como desee. Ejemplo:
type maybeNaN struct{
isNan bool
number float64
}
func (n maybeNaN) MarshalJSON() ([]byte, error) {
if n.isNan {
return []byte("null"), nil // Or whatever you want here
}
return json.Marshal(n.number)
}
func (n *maybeNan) UnmarshalJSON(p []byte) error {
if string(p) == "NaN" {
n.isNan = true
return nil
}
return json.Unmarshal(p, &n.number)
}
type myStruct struct {
someNumber maybeNaN `json:"someNumber" bson:"someNumber"`
/* ... */
}
Si tiene una estructura arbitraria de su BSON, su única opción es atravesar la estructura, usar la reflexión y convertir cualquier ocurrencia de NaN en un tipo (posiblemente un tipo personalizado como se describe arriba)