on master help sign in
Ensure that we parse null as NaN when expecting a floating point number.
commit2a6f490beacc830c94468920f83c3bd65f97fa57 authorBryan O'Sullivan <bos@mailrank.com> dateWed 13 Apr 2011, 09:46 (16 years ago) parenta52ccd0
1 file changed+3
Data/Aeson/Types.hs+3
Data/Aeson/Types.hs+3
@@ -367,6 +367,7 @@ instance FromJSON Double where
367367 parseJSON (Number n) = case n of
368368 D d -> pure d
369369 I i -> pure (fromIntegral i)
370+ parseJSON Null = pure (0/0)
370371 parseJSON v = typeMismatch "Double" v
371372 {-# INLINE parseJSON #-}
372373
@@ -376,6 +377,7 @@ instance ToJSON Number where
376377
377378instance FromJSON Number where
378379 parseJSON (Number n) = pure n
380+ parseJSON Null = pure (D (0/0))
379381 parseJSON v = typeMismatch "Number" v
380382 {-# INLINE parseJSON #-}
381383
@@ -387,6 +389,7 @@ instance FromJSON Float where
387389 parseJSON (Number n) = case n of
388390 D d -> pure . fromRational . toRational $ d
389391 I i -> pure (fromIntegral i)
392+ parseJSON Null = pure (0/0)
390393 parseJSON v = typeMismatch "Float" v
391394 {-# INLINE parseJSON #-}
392395