@@ -65,7 +65,6 @@ module Servant.API.ContentTypes
6565 , AllMime (.. )
6666 , AllMimeRender (.. )
6767 , AllMimeUnrender (.. )
68- , eitherDecodeLenient
6968 , canHandleAcceptH
7069 ) where
7170
@@ -75,13 +74,7 @@ import Control.Monad.Compat
7574import Control.DeepSeq
7675 (NFData )
7776import Data.Aeson
78- (FromJSON (.. ), ToJSON (.. ), encode )
79- import Data.Aeson.Parser
80- (value )
81- import Data.Aeson.Types
82- (parseEither )
83- import Data.Attoparsec.ByteString.Char8
84- (endOfInput , parseOnly , skipSpace , (<?>) )
77+ (FromJSON (.. ), ToJSON (.. ), encode , eitherDecode )
8578import Data.Bifunctor
8679 (bimap )
8780import qualified Data.ByteString as BS
@@ -371,28 +364,9 @@ instance NFData NoContent
371364--------------------------------------------------------------------------
372365-- * MimeUnrender Instances
373366
374- -- | Like 'Data.Aeson.eitherDecode' but allows all JSON values instead of just
375- -- objects and arrays.
376- --
377- -- Will handle trailing whitespace, but not trailing junk. ie.
378- --
379- -- >>> eitherDecodeLenient "1 " :: Either String Int
380- -- Right 1
381- --
382- -- >>> eitherDecodeLenient "1 junk" :: Either String Int
383- -- Left "trailing junk after valid JSON: endOfInput"
384- eitherDecodeLenient :: FromJSON a => ByteString -> Either String a
385- eitherDecodeLenient input =
386- parseOnly parser (cs input) >>= parseEither parseJSON
387- where
388- parser = skipSpace
389- *> Data.Aeson.Parser. value
390- <* skipSpace
391- <* (endOfInput <?> " trailing junk after valid JSON" )
392-
393367-- | `eitherDecode`
394368instance FromJSON a => MimeUnrender JSON a where
395- mimeUnrender _ = eitherDecodeLenient
369+ mimeUnrender _ = eitherDecode
396370
397371-- | @urlDecodeAsForm@
398372-- Note that the @mimeUnrender p (mimeRender p x) == Right x@ law only
0 commit comments