bytestring-aeson-orphans (empty) → 0.1.0.0
raw patch · 5 files changed
+108/−0 lines, 5 filesdep +aesondep +basedep +base64-bytestring
Dependencies added: aeson, base, base64-bytestring, bytestring, text
Files
- CHANGELOG.md +4/−0
- LICENSE +30/−0
- README.md +7/−0
- bytestring-aeson-orphans.cabal +39/−0
- src/ByteString/Aeson/Orphans.hs +28/−0
+ CHANGELOG.md view
@@ -0,0 +1,4 @@+# Revision history for bytestring-aeson-orphans++## 2021-11-17+* First changes. Added code for bytestring JSON instances using AESON.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2021, Obsidian Systems LLC++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Obsidian Systems LLC nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,7 @@+# bytestring-aeson-orphans+[](https://haskell.org) [](https://hackage.haskell.org/package/bytestring-aeson-orphans) [](https://matrix.hackage.haskell.org/#/package/bytestring-aeson-orphans) [](https://travis-ci.org/obsidiansystems/bytestring-aeson-orphans) [](https://github.com/obsidiansystems/bytestring-aeson-orphans/actions) [](https://github.com/obsidiansystems/bytestring-aeson-orphans/blob/master/LICENSE)++_Aeson instances for ByteString, using base 64 encoding._++***+[](https://obsidian.systems)
+ bytestring-aeson-orphans.cabal view
@@ -0,0 +1,39 @@+cabal-version: 2.4+name: bytestring-aeson-orphans+version: 0.1.0.0+synopsis: Aeson instances for ByteString, using base 64 encoding+description:+ Encode ByteStrings as valid JSON using Aeson. The instances provided by this+ package use base64 encoding to ensure that the ByteString does not contain+ invalid (for JSON) characters.++homepage: https://github.com/obsidiansystems/bytestring-aeson-orphans+bug-reports:+ https://github.com/obsidiansystems/bytestring-aeson-orphans/issues++license: BSD-3-Clause+license-file: LICENSE+author: Obsidian Systems LLC+maintainer: maintainer@obsidian.systems+copyright: (c) 2021 Obsidian Systems LLC+category: Data+extra-source-files: CHANGELOG.md README.md++library+ hs-source-dirs: src++ build-depends:+ aeson >= 1.4 && < 2+ , base >= 4.10 && < 5+ , base64-bytestring >= 1.0 && < 1.3+ , bytestring >= 0.10 && < 0.12+ , text >= 1 && < 1.3++ exposed-modules: ByteString.Aeson.Orphans++ ghc-options: -Wall+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/obsidiansystems/bytestring-aeson-orphans
+ src/ByteString/Aeson/Orphans.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE DerivingStrategies #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE StandaloneDeriving #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}++module ByteString.Aeson.Orphans where++import Data.Aeson+import Data.ByteString (ByteString)+import qualified Data.ByteString.Base64 as B64+import qualified Data.ByteString.Lazy as LBS+import Data.Text.Encoding (decodeUtf8, encodeUtf8)++instance ToJSON ByteString where+ toJSON = toJSON . decodeUtf8 . B64.encode++instance FromJSON ByteString where+ parseJSON o = either fail return . B64.decode . encodeUtf8 =<< parseJSON o++instance ToJSON LBS.ByteString where+ toJSON = toJSON . decodeUtf8 . B64.encode . LBS.toStrict++instance FromJSON LBS.ByteString where+ parseJSON o = either fail (return . LBS.fromStrict) . B64.decode . encodeUtf8 =<< parseJSON o++instance ToJSONKey ByteString+instance FromJSONKey ByteString