-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Derivation of Aeson instances using GHC generics.
--   
--   Derivation of Aeson instances using GHC generics.
@package generic-aeson
@version 0.2.0.9


-- | Test if a data type is an enumeration (only zero-argument
--   constructors) generically using <a>GHC.Generics</a>.
module Generics.Generic.IsEnum

-- | Generically test if a data type is an enumeration.
isEnum :: forall a. (Generic a, GIsEnum (Rep a)) => Proxy a -> Bool

-- | Class for testing if the functors from <a>GHC.Generics</a> are
--   enumerations. You generally don't need to give any custom instances.
--   Just call <a>isEnum</a>.
class GIsEnum f
gIsEnum :: GIsEnum f => Proxy (f a) -> Bool
instance Generics.Generic.IsEnum.GIsEnum GHC.Generics.V1
instance Generics.Generic.IsEnum.GIsEnum (GHC.Generics.K1 i a)
instance Generics.Generic.IsEnum.GIsEnum GHC.Generics.U1
instance Generics.Generic.IsEnum.GIsEnum GHC.Generics.Par1
instance Generics.Generic.IsEnum.GIsEnum (GHC.Generics.Rec1 f)
instance (Generics.Generic.IsEnum.GIsEnum f, Generics.Generic.IsEnum.GIsEnum g) => Generics.Generic.IsEnum.GIsEnum (f GHC.Generics.:+: g)
instance (Generics.Generic.IsEnum.GIsEnum f, Generics.Generic.IsEnum.GIsEnum g) => Generics.Generic.IsEnum.GIsEnum (f GHC.Generics.:*: g)
instance Generics.Generic.IsEnum.GIsEnum f => Generics.Generic.IsEnum.GIsEnum (GHC.Generics.M1 GHC.Generics.C c f)
instance Generics.Generic.IsEnum.GIsEnum (GHC.Generics.M1 GHC.Generics.S c a)
instance Generics.Generic.IsEnum.GIsEnum f => Generics.Generic.IsEnum.GIsEnum (GHC.Generics.M1 GHC.Generics.D c f)


-- | Helper functions that can be reused by libraries interoperating with
--   generic-aeson.
module Generics.Generic.Aeson.Util

-- | Lowercases the first letter and strips leading and trailing
--   underscores.
formatLabel :: Settings -> Text -> Text
multipleConstructors :: [a] -> Bool
conNameT :: forall (t :: * -> Meta -> (* -> *) -> * -> *) i c (f :: * -> *) p. Constructor c => Settings -> t i c f p -> Text
selNameT :: forall (t :: * -> Meta -> (* -> *) -> * -> *) i s (f :: * -> *) p. Selector s => Settings -> t i s f p -> Maybe Text
data Settings
Settings :: Maybe String -> Settings
[stripPrefix] :: Settings -> Maybe String
defaultSettings :: Settings
instance GHC.Show.Show Generics.Generic.Aeson.Util.Settings


-- | This module offers generic conversions to and from JSON <a>Value</a>s
--   for data types with a <a>Generic</a> instance.
--   
--   The structure of the generated JSON is meant to be close to idiomatic
--   JSON. This means:
--   
--   <ul>
--   <li>Enumerations are converted to JSON strings.</li>
--   <li>Record fields become JSON keys.</li>
--   <li>Data types with one unlabeled field convert to just that
--   field.</li>
--   <li>Data types with multiple unlabeled fields become arrays.</li>
--   <li>Multiple constructors are represented by keys.</li>
--   <li><a>Maybe</a> values are either an absent key, or the value.</li>
--   </ul>
--   
--   See 'tests/Main.hs' for more examples.
module Generics.Generic.Aeson

-- | Convert any datatype with a <a>Generic</a> instance to a JSON
--   <a>Value</a>.
gtoJson :: forall a. (Generic a, GtoJson (Rep a), ConNames (Rep a), GIsEnum (Rep a)) => a -> Value

-- | Parse any datatype with a <a>Generic</a> instance from a JSON
--   <a>Value</a>.
gparseJson :: forall a. (Generic a, GfromJson (Rep a), ConNames (Rep a), GIsEnum (Rep a)) => Value -> Parser a

-- | Class for converting the functors from <a>GHC.Generics</a> to JSON.
--   You generally don't need to give any custom instances. Just add
--   'deriving Generic' and call <tt>gToJson</tt>.
class GtoJson f

-- | Generically show a functor as a JSON value. The first argument tells
--   us if there are multiple constructors in the data type. The second
--   indicates if this data type is an enumeration (only empty
--   constructors). A functor is then converted to either a list of values
--   (for non-labeled fields) or a list of String/value pairs (for labeled
--   fields).
gtoJSONf :: GtoJson f => Settings -> Bool -> Bool -> f a -> Either [Value] [(Text, Value)]

-- | Class for parsing the functors from <a>GHC.Generics</a> from JSON. You
--   generally don't need to give any custom instances. Just add 'deriving
--   Generic' and call <tt>gFromJson</tt>.
class GfromJson f

-- | Generically read a functor from a JSON value. The first argument tells
--   us if there are multiple constructors in the data type. The second
--   indicates if we've already detected that this data type has multiple
--   constructors. When this is False, the (:*:) puts the fields in the
--   state. The third indicates if this data type is an enumeration (only
--   empty constructors). The third is a function for parsing the recursive
--   positions. A JSON value is then parsed to either a functor, or a
--   failure.
gparseJSONf :: GfromJson f => Settings -> Bool -> Bool -> Bool -> StateT [Value] Parser (f a)

-- | Lowercases the first letter and strips leading and trailing
--   underscores.
formatLabel :: Settings -> Text -> Text
data Settings
Settings :: Maybe String -> Settings
[stripPrefix] :: Settings -> Maybe String
defaultSettings :: Settings
gtoJsonWithSettings :: forall a. (Generic a, GtoJson (Rep a), ConNames (Rep a), GIsEnum (Rep a)) => Settings -> a -> Value
gparseJsonWithSettings :: forall a. (Generic a, GfromJson (Rep a), ConNames (Rep a), GIsEnum (Rep a)) => Settings -> Value -> Parser a
instance Generics.Generic.Aeson.GtoJson GHC.Generics.U1
instance Generics.Generic.Aeson.GfromJson GHC.Generics.U1
instance Data.Aeson.Types.ToJSON.ToJSON c => Generics.Generic.Aeson.GtoJson (GHC.Generics.K1 a c)
instance Data.Aeson.Types.FromJSON.FromJSON c => Generics.Generic.Aeson.GfromJson (GHC.Generics.K1 a c)
instance (Generics.Generic.Aeson.GtoJson f, Generics.Generic.Aeson.GtoJson g) => Generics.Generic.Aeson.GtoJson (f GHC.Generics.:+: g)
instance (Generics.Generic.Aeson.GfromJson f, Generics.Generic.Aeson.GfromJson g) => Generics.Generic.Aeson.GfromJson (f GHC.Generics.:+: g)
instance (Generics.Generic.Aeson.GtoJson f, Generics.Generic.Aeson.GtoJson g) => Generics.Generic.Aeson.GtoJson (f GHC.Generics.:*: g)
instance (Generics.Generic.Aeson.GfromJson f, Generics.Generic.Aeson.GfromJson g) => Generics.Generic.Aeson.GfromJson (f GHC.Generics.:*: g)
instance Generics.Generic.Aeson.GtoJson f => Generics.Generic.Aeson.GtoJson (GHC.Generics.M1 GHC.Generics.D c f)
instance Generics.Generic.Aeson.GfromJson f => Generics.Generic.Aeson.GfromJson (GHC.Generics.M1 GHC.Generics.D c f)
instance (GHC.Generics.Constructor c, Generics.Generic.Aeson.GtoJson f) => Generics.Generic.Aeson.GtoJson (GHC.Generics.M1 GHC.Generics.C c f)
instance (GHC.Generics.Constructor c, Generics.Generic.Aeson.GfromJson f) => Generics.Generic.Aeson.GfromJson (GHC.Generics.M1 GHC.Generics.C c f)
instance (GHC.Generics.Selector c, Generics.Generic.Aeson.GtoJson f) => Generics.Generic.Aeson.GtoJson (GHC.Generics.M1 GHC.Generics.S c f)
instance (GHC.Generics.Selector c, Generics.Generic.Aeson.GfromJson f) => Generics.Generic.Aeson.GfromJson (GHC.Generics.M1 GHC.Generics.S c f)
instance (GHC.Generics.Selector c, Data.Aeson.Types.ToJSON.ToJSON a) => Generics.Generic.Aeson.GtoJson (GHC.Generics.M1 GHC.Generics.S c (GHC.Generics.K1 i (GHC.Base.Maybe a)))
instance (GHC.Generics.Selector c, Data.Aeson.Types.FromJSON.FromJSON a) => Generics.Generic.Aeson.GfromJson (GHC.Generics.M1 GHC.Generics.S c (GHC.Generics.K1 i (GHC.Base.Maybe a)))
