summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-26 08:57:03 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-26 08:57:03 +0400
commit918bb023aec3a49298003ec87da341d744190320 (patch)
tree71faf477230b1df25eae1e286a439530dd947770 /src/Data
parentc1b4289459faa1fd0c982472d3eeaa2d772fbfdf (diff)
Bump aeson dependency
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Torrent/JSON.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs
index 3fa8973d..6a0aa510 100644
--- a/src/Data/Torrent/JSON.hs
+++ b/src/Data/Torrent/JSON.hs
@@ -3,9 +3,14 @@ module Data.Torrent.JSON
3 , omitRecordPrefix 3 , omitRecordPrefix
4 ) where 4 ) where
5 5
6import Control.Applicative
6import Data.Aeson.TH 7import Data.Aeson.TH
8import Data.Aeson.Types
9import Data.ByteString as BS
10import Data.ByteString.Base16 as Base16
7import Data.Char 11import Data.Char
8import Data.List as L 12import Data.List as L
13import Data.Text.Encoding as T
9 14
10 15
11-- | Ignore '_' prefix. 16-- | Ignore '_' prefix.
@@ -28,4 +33,14 @@ mapWhile p f = go
28omitRecordPrefix :: Options 33omitRecordPrefix :: Options
29omitRecordPrefix = omitLensPrefix 34omitRecordPrefix = omitLensPrefix
30 { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower 35 { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower
31 } \ No newline at end of file 36 }
37
38instance ToJSON ByteString where
39 toJSON = String . T.decodeUtf8 . Base16.encode
40
41instance FromJSON ByteString where
42 parseJSON v = do
43 (ok, bad) <- (Base16.decode . T.encodeUtf8) <$> parseJSON v
44 if BS.null bad
45 then return ok
46 else fail "parseJSON: unable to decode ByteString"