on master help sign in
Merge pull request #441 from phadej/docs-and-changelog

Docs and changelog

commitfb484e459dbcdf855519a34451cf49b6446c4ead authorAdam Bergmark <adam@bergmark.nl> dateMon 4 Jul 2016, 15:19 (10 years ago) parente8436e2e6f597b
3 files changed+23
Data/Aeson/Types/FromJSON.hs+1 Data/Aeson/Types/ToJSON.hs+16 changelog.md+6
Data/Aeson/Types/FromJSON.hs+1
@@ -548,6 +548,7 @@ parseJSON2 = liftParseJSON2 parseJSON parseJSONList parseJSON parseJSONList
548548-- List functions
549549-------------------------------------------------------------------------------
550550
551+-- | Helper function to use with 'liftParseJSON'. See 'Data.Aeson.ToJSON.listEncoding'.
551552listParser :: (Value -> Parser a) -> Value -> Parser [a]
552553listParser f (Array xs) = fmap V.toList (V.mapM f xs)
553554listParser _ v = typeMismatch "[a]" v
Data/Aeson/Types/ToJSON.hs+16
@@ -580,9 +580,25 @@ toEncoding2 = liftToEncoding2 toEncoding toEncodingList toEncoding toEncodingLis
580580-- Encoding functions
581581-------------------------------------------------------------------------------
582582
583+-- | Helper function to use with 'liftToEncoding'.
584+-- Useful when writing own 'ToJSON1' instances.
585+--
586+-- @
587+-- newtype F a = F [a]
588+--
589+-- -- This instance encodes String as an array of chars
590+-- instance 'ToJSON1' F where
591+-- 'liftToJSON' tj _ (F xs) = 'liftToJSON' tj ('listValue' tj) xs
592+-- 'liftToEncoding' te _ (F xs) = 'liftToEncoding' te ('listEncoding' te) xs
593+--
594+-- instance 'Data.Aeson.FromJSON.FromJSON1' F where
595+-- 'Data.Aeson.FromJSON.liftParseJSON' p _ v = F \<$\> 'Data.Aeson.FromJSON.liftParseJSON' p ('Data.Aeson.FromJSON.listParser' p) v
596+-- @
583597listEncoding :: (a -> Encoding) -> [a] -> Encoding
584598listEncoding = E.list
599+{-# INLINE listEncoding #-}
585600
601+-- | Helper function to use with 'liftToJSON', see 'listEncoding'.
586602listValue :: (a -> Value) -> [a] -> Value
587603listValue f = Array . V.fromList . map f
588604{-# INLINE listValue #-}
changelog.md+6
@@ -11,6 +11,8 @@ For the latest version of this document, please see [https://github.com/bos/aeso
1111* Modified instances for `Map` and `HashMap`. Introduced new `FromJSONKey` and
1212 `ToJSONKey` type classes.
1313
14+* Added `Data.Aeson.Encoding` with functions to work with `Encoding` in an abstract way.
15+
1416* Export `decodeWith`, `decodeStrictWith`, `eitherDecodeWith`, and
1517 `eitherDecodeStrictWith` from `Data.Aeson.Parser`. This allows
1618 decoding using explicit parsers instead of using `FromJSON`
@@ -37,6 +39,10 @@ For the latest version of this document, please see [https://github.com/bos/aeso
3739* `ToJSON` instances using `genericToEncoding` and `omitNothingFields`
3840 no longer produces invalid JSON.
3941
42+* Added instances for `DList`, `Compose`, `Product`, `Sum`.
43+
44+* Buildable with `bytestring-0.9` (with a help of `bytestring-builder` compatibility package).
45+
4046### 0.11.2.0
4147
4248* Enable `PolyKinds` to generalize `Proxy`, `Tagged`, and `Const` instances.