aeson-deriving-0.1.0.0: data types for compositional, type-directed serialization

Safe HaskellNone
LanguageHaskell2010

Data.Aeson.Deriving.Internal.Generic

Synopsis

Documentation

class ToAesonOptions a where Source #

A class for defining Options for Aeson's Generic deriving support. It is generally instantiated either by specifying all Options fields, using GenericOptions, or simply be overriding a few specific fields, by giving a (type-level) list. In both cases, for the sake of explicitness and to reduce the possibility of mistakes, fields are specified in a record-like form using the '(:=)' data type.

Users may also provide their own instances for their own data types if desired, but this should not generally be necessary.

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

ToAesonOptions ([] :: [k]) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

(TypeError ToAesonOptionsListError :: Constraint) => ToAesonOptions ([a] :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

(ToAesonOptionsField x, ToAesonOptions xs) => ToAesonOptions (x ': xs :: [a]) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (x ': xs) -> Options Source #

(TypeError ToAesonOptionsListError :: Constraint) => ToAesonOptions [] Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

type ToAesonOptionsListError = ((((((((((((((Text "aeson-deriving constraint error for ToAesonOptions class:" :$$: Text "Don't forget to \"tick\" your opening list bracket.") :$$: Text "There is no ToAesonOptions instance for list types.") :$$: Text "Rather, there are instances for promoted list values.") :$$: Text "") :$$: Text "You likely should correct your deriving declaration to something like:") :$$: Text "") :$$: Text " via GenericEncoded '[myVal1,..]") :$$: Text "") :$$: Text "Instead of:") :$$: Text "") :$$: Text " via GenericEncoded [myVal1,..]") :$$: Text "") :$$: Text "For explanation, see GHC documentation on datatype promotion:") :$$: Text "https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#datatype-promotion") :$$: Text "" Source #

class ToAesonOptionsField x where Source #

A class that knows about fields of aeson's Options.

Instances
KnownBool b => ToAesonOptionsField (TagSingleConstructors := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

KnownBool b => ToAesonOptionsField (UnwrapUnaryRecords := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

KnownBool b => ToAesonOptionsField (OmitNothingFields := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

KnownBool b => ToAesonOptionsField (AllNullaryToStringTag := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction f => ToAesonOptionsField (ConstructorTagModifier := f :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction f => ToAesonOptionsField (FieldLabelModifier := f :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

ToSumEncoding se => ToAesonOptionsField (SumEncoding := se :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data FieldLabelModifier Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

StringFunction f => ToAesonOptionsField (FieldLabelModifier := f :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data ConstructorTagModifier Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

StringFunction f => ToAesonOptionsField (ConstructorTagModifier := f :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data AllNullaryToStringTag Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

KnownBool b => ToAesonOptionsField (AllNullaryToStringTag := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data OmitNothingFields Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

KnownBool b => ToAesonOptionsField (OmitNothingFields := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data UnwrapUnaryRecords Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

KnownBool b => ToAesonOptionsField (UnwrapUnaryRecords := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data TagSingleConstructors Source #

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

KnownBool b => ToAesonOptionsField (TagSingleConstructors := b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data GenericOptions :: fieldLabelModifier -> constructorTagModifier -> allNullaryToStringTag -> omitNothingFields -> sumEncoding -> unwrapUnaryRecords -> tagSingleConstructors -> Type Source #

Type-level representation of the Aeson Generic deriving Options. This representation is useful explicitly setting all options.

Instances
(All (StringFunction :: k2 -> Constraint) (fieldLabelModifier ': (constructorTagModifier ': ([] :: [k2]))), ToSumEncoding sumEncoding, All KnownBool (allNullaryToStringTag ': (omitNothingFields ': (unwrapUnaryRecords ': (tagSingleConstructors ': ([] :: [Bool])))))) => ToAesonOptions (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors) :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toAesonOptions :: Proxy (GenericOptions (FieldLabelModifier := fieldLabelModifier) (ConstructorTagModifier := constructorTagModifier) (AllNullaryToStringTag := allNullaryToStringTag) (OmitNothingFields := omitNothingFields) (SumEncoding := sumEncoding) (UnwrapUnaryRecords := unwrapUnaryRecords) (TagSingleConstructors := tagSingleConstructors)) -> Options Source #

newtype GenericEncoded opts a Source #

Specify your encoding scheme in terms of aeson's out-of-the box Generic functionality. This type is never used directly, only "coerced through". Use some of the pre-defined types supplied here for the opts phantom parameter, or define your with an instance of ToAesonOptions.

Constructors

GenericEncoded a 

type family LoopWarning (n :: Type -> Type) (a :: Type) :: Constraint where ... Source #

Used in FromJSON/ToJSON superclass constraints for newtypes that recursively modify the instances. A guard against the common mistake of deriving encoders in terms of such a newtype over the naked base type instead of the GenericEncoded version. This can lead to nasty runtime bugs.

This error can be disabled by wrapping your type in DisableLoopWarning. This should never be necessary to use the functionality of this package. It may be required if you, for example, combine our newtypes with another library's types for generating aeson instances.

Equations

LoopWarning n (GenericEncoded opts a) = () 
LoopWarning n (RecordSumEncoded tagKey tagValMod a) = () 
LoopWarning n (DisableLoopWarning a) = () 
LoopWarning n (x & f) = LoopWarning n (f x) 
LoopWarning n (f x) = LoopWarning n x 
LoopWarning n x = TypeError (((((((((((((((((Text "Uh oh! Watch out for those infinite loops!" :$$: Text "Newtypes that recursively modify aeson instances, namely:") :$$: Text "") :$$: (Text " " :<>: ShowType n)) :$$: Text "") :$$: Text "must only be used atop a type that creates the instances non-recursively: ") :$$: Text "") :$$: Text " \65518 GenericEncoded") :$$: Text " \65518 RecordSumEncoded") :$$: Text "") :$$: Text "We observe instead the inner type: ") :$$: Text "") :$$: (Text " " :<>: ShowType x)) :$$: Text "") :$$: Text "You probably created an infinitely recursive encoder/decoder pair.") :$$: Text "See `LoopWarning` for details.") :$$: Text "This check can be disabled by wrapping the inner type in `DisableLoopWarning`.") :$$: Text "") 

newtype DisableLoopWarning a Source #

Assert that you know what you're doing and to nullify the LoopWarning constraint family. This should not be necessary.

Constructors

DisableLoopWarning a 

newtype RecordSumEncoded (tagKey :: Symbol) (tagModifier :: k) (a :: Type) Source #

An encoding scheme for sums of records that are defined as distinct data types. If we have a number of record types we want to combine under a sum, a straightforward solution is to ensure that each each inner type uses a constructor tag, and then derive the sum with SumEncoding := UntaggedValue. This works fine for the happy path, but makes for very bad error messages, since it means that decoding proceeds by trying each case in sequence. Thus error messages always pertain to the last type in the sum, even when it wasn't the intended payload. This newtype improves on that solution by providing the relevant error messages, by remembering the correspondence between the constructor tag and the intended inner type/parser.

In order to work correctly, the inner types must use the TaggedObject encoding. The same tag field name and ConstructorTagModifier must be supplied to this type.

Constructors

RecordSumEncoded a 
Instances
(Generic a, GToJSON Zero (Rep a)) => ToJSON (RecordSumEncoded tagKey tagModifier a) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toJSON :: RecordSumEncoded tagKey tagModifier a -> Value #

toEncoding :: RecordSumEncoded tagKey tagModifier a -> Encoding #

toJSONList :: [RecordSumEncoded tagKey tagModifier a] -> Value #

toEncodingList :: [RecordSumEncoded tagKey tagModifier a] -> Encoding #

(Generic a, GFromJSON Zero (Rep a), GTagParserMap (Rep a), Rep a ~ D1 meta cs, Datatype meta, StringFunction tagModifier, KnownSymbol tagKey) => FromJSON (RecordSumEncoded tagKey tagModifier a) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

parseJSON :: Value -> Parser (RecordSumEncoded tagKey tagModifier a) #

parseJSONList :: Value -> Parser [RecordSumEncoded tagKey tagModifier a] #

stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] Source #

dropPrefix :: Eq a => [a] -> [a] -> [a] Source #

dropSuffix :: Eq a => [a] -> [a] -> [a] Source #

class StringFunction (a :: k) where Source #

Instances
StringFunction DropLowercasePrefix Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction Lowercase Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction Uppercase Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction SnakeCase Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction Id Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

StringFunction ([] :: [k]) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

KnownSymbol str => StringFunction (DropSuffix str :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

KnownSymbol str => StringFunction (DropPrefix str :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

(StringFunction x, StringFunction xs) => StringFunction (x ': xs :: [a]) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

stringFunction :: Proxy (x ': xs) -> String -> String Source #

All KnownSymbol (a ': (b ': ([] :: [Symbol]))) => StringFunction (a ==> b :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

stringFunction :: Proxy (a ==> b) -> String -> String Source #

data Id Source #

data DropLowercasePrefix Source #

Applies dropLowercasePrefix, dropping until the first uppercase character.

data DropPrefix (str :: Symbol) Source #

Instances
KnownSymbol str => StringFunction (DropPrefix str :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data DropSuffix (str :: Symbol) Source #

Instances
KnownSymbol str => StringFunction (DropSuffix str :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

data TaggedObject (tagFieldName :: Symbol) (contentsFieldName :: Symbol) Source #

A constructor will be encoded to an object with a field tagFieldName which specifies the constructor tag (modified by the constructorTagModifier). If the constructor is a record the encoded record fields will be unpacked into this object. So make sure that your record doesn't have a field with the same label as the tagFieldName. Otherwise the tag gets overwritten by the encoded value of that field! If the constructor is not a record the encoded constructor contents will be stored under the contentsFieldName field.

Instances
(KnownSymbol tag, KnownSymbol contents) => ToSumEncoding (TaggedObject tag contents :: Type) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toSumEncoding :: Proxy (TaggedObject tag contents) -> SumEncoding Source #

snakeCase :: String -> String Source #

Field name modifier function that separates camel-case words by underscores (i.e. on capital letters). Also knows to handle a consecutive sequence of capitals as a single word.

dropLowercasePrefix :: String -> String Source #

Drop the first lowercase sequence (i.e. until isUpper returns True) from the start of a string. Used for the common idiom where fields are prefixed by the type name in all lowercase. The definition is taken from the aeson-casing package.

newtype x & f infixl 2 Source #

Constructors

Ampersand 

Fields

Instances
ToJSON (f x) => ToJSON (x & f) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

toJSON :: (x & f) -> Value #

toEncoding :: (x & f) -> Encoding #

toJSONList :: [x & f] -> Value #

toEncodingList :: [x & f] -> Encoding #

FromJSON (f x) => FromJSON (x & f) Source # 
Instance details

Defined in Data.Aeson.Deriving.Internal.Generic

Methods

parseJSON :: Value -> Parser (x & f) #

parseJSONList :: Value -> Parser [x & f] #