git.iko.soy/typeable/postgresql-simple
on master help sign in
Check type before null in FromField json instance
d535150Leon P Smith
src/Database/PostgreSQL/Simple/FromField.hs+9−8
@@ -446,14 +446,15 @@ fromArray typeInfo f = sequence . (parseIt <$>) <$> array delim
446
446
447-- | json
447-- | json
448instance FromField JSON.Value where
448instance FromField JSON.Value where
449− fromField f Nothing = returnError UnexpectedNull f ""
449+ fromField f mbs =
450− fromField f (Just bs)
451− | typeOid f /= $(inlineTypoid TI.json) =
450+ if typeOid f /= $(inlineTypoid TI.json)
452− returnError Incompatible f ""
451+ then returnError Incompatible f ""
453− | otherwise =
452+ else case mbs of
453+ Nothing -> returnError UnexpectedNull f ""
454+ Just bs ->
454− case JSON.eitherDecode' $ LB.fromStrict bs of
455+ case JSON.eitherDecode' $ LB.fromStrict bs of
455− Left err -> returnError ConversionFailed f err
456+ Left err -> returnError ConversionFailed f err
456− Right val -> pure val
457+ Right val -> pure val
457
458
458-- | Parse a field to a JSON 'JSON.Value' and convert that into a
459-- | Parse a field to a JSON 'JSON.Value' and convert that into a
459-- Haskell value using 'JSON.fromJSON'.
460-- Haskell value using 'JSON.fromJSON'.