summaryrefslogtreecommitdiffstats
path: root/src/Data/ByteString/Extended.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/ByteString/Extended.hs')
-rw-r--r--src/Data/ByteString/Extended.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Data/ByteString/Extended.hs b/src/Data/ByteString/Extended.hs
new file mode 100644
index 0000000..144c933
--- /dev/null
+++ b/src/Data/ByteString/Extended.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE FlexibleInstances #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Data.ByteString.Extended
+ (
+ ) where
+
+import Data.Aeson
+import Data.ByteString
+import qualified Data.CaseInsensitive
+import Data.Text.Encoding
+import qualified Data.Text.Encoding.Error
+
+
+instance FromJSON ByteString where
+ parseJSON =
+ withText "ByteString" $
+ pure . Data.Text.Encoding.encodeUtf8
+
+instance ToJSON Data.ByteString.ByteString where
+ toJSON =
+ String .
+ Data.Text.Encoding.decodeUtf8With
+ Data.Text.Encoding.Error.lenientDecode
+
+
+instance ToJSON (Data.CaseInsensitive.CI Data.ByteString.ByteString) where
+ toJSON =
+ toJSON . Data.CaseInsensitive.foldedCase
+
+instance FromJSON (Data.CaseInsensitive.CI Data.ByteString.ByteString) where
+ parseJSON =
+ withText "CI ByteString" $
+ pure . Data.CaseInsensitive.mk . Data.Text.Encoding.encodeUtf8