git.iko.soy/typeable/postgresql-simple
on master help sign in
Check type before null in FromField json instance
commitd53515083fc4ceaf8e23baecf361d341d9f800a0 authorLeon P Smith <leon@melding-monads.com> dateWed 11 Sep 2013, 19:58 (13 years ago) parent992cbbf
1 file changed+9−8
src/Database/PostgreSQL/Simple/FromField.hs+9−8
src/Database/PostgreSQL/Simple/FromField.hs+9−8
@@ -446,14 +446,15 @@ fromArray typeInfo f = sequence . (parseIt <$>) <$> array delim
446446
447447-- | json
448448instance FromField JSON.Value where
449− fromField f Nothing = returnError UnexpectedNull f ""
450− fromField f (Just bs)
451− | typeOid f /= $(inlineTypoid TI.json) =
452− returnError Incompatible f ""
453− | otherwise =
454− case JSON.eitherDecode' $ LB.fromStrict bs of
455− Left err -> returnError ConversionFailed f err
456− Right val -> pure val
449+ fromField f mbs =
450+ if typeOid f /= $(inlineTypoid TI.json)
451+ then returnError Incompatible f ""
452+ else case mbs of
453+ Nothing -> returnError UnexpectedNull f ""
454+ Just bs ->
455+ case JSON.eitherDecode' $ LB.fromStrict bs of
456+ Left err -> returnError ConversionFailed f err
457+ Right val -> pure val
457458
458459-- | Parse a field to a JSON 'JSON.Value' and convert that into a
459460-- Haskell value using 'JSON.fromJSON'.