Safe Haskell | None |
---|---|
Language | Haskell2010 |
Jordan.Generic.Options
Synopsis
- type Representational (f :: * -> *) = forall a b. Coercible a b => Coercible (f a) (f b) :: Constraint
- data SumTypeEncoding
- = TagVal
- | TagInField
- type family AllNullary cons where ...
- newtype PartOfSum f a = MkPartOfSum {
- getPartOfSum :: f a
- newtype WithOptions (options :: [*]) a = WithOptions {
- getWithOptions :: a
- data OmitNothingFields = OmitNothingFields
- data KeepNothingFields = KeepNothingFields
- fullyQualifyName :: TypeRep -> Text
Documentation
type Representational (f :: * -> *) = forall a b. Coercible a b => Coercible (f a) (f b) :: Constraint Source #
data SumTypeEncoding Source #
Constructors
TagVal | |
TagInField |
Instances
type family AllNullary cons where ... Source #
Equations
AllNullary (C1 ('MetaCons _ _ 'False) (S1 ('MetaSel 'Nothing _ _ _) U1)) = True | |
AllNullary (a :+: b) = AllNullary a && AllNullary b | |
AllNullary _ = False |
newtype PartOfSum f a Source #
Constructors
MkPartOfSum | |
Fields
|
Instances
newtype WithOptions (options :: [*]) a Source #
A newtype wrapper, designed to make it easier to derive ToJSON and FromJSON instances.
The API of abstract JSON serializing is awkward due to the somewhat bad ergonomics of the
Divisible
and (especially)
Decidable
typeclasses.
In general, using -XDerivingVia
, -XDeriveGeneric
, -XDataKinds
and this wrapper will make your life much easier.
Unfortunately, due to a weird GHC quirk, you also need -XDerivingVia
.
That is, the following won't work, complaining about role errors:
data PersonFilter = PersonFilter { filterFirstName :: Maybe Text, filterLastName :: Maybe Text } deriving (Show, Generic) deriving (ToJSON, FromJSON) via (WithOptions '[KeepNothingFields] PersonFilter)
But this will:
data PersonFilter = PersonFilter { filterFirstName :: Maybe Text, filterLastName :: Maybe Text } deriving (Show, Generic) deriving via (WithOptions '[KeepNothingFields] PersonFilter) instance (ToJSON PersonFilter) deriving via (WithOptions '[KeepNothingFields] PersonFilter) instance (FromJSON PersonFilter)
Constructors
WithOptions | |
Fields
|
Instances
data OmitNothingFields Source #
Newtype for use with GeneralizedNewtypeDeriving. Will have us omit Nothing fields for parsing and serializing.
Constructors
OmitNothingFields |
Instances
SpecifiesFromJSONOptions xs => SpecifiesFromJSONOptions (OmitNothingFields ': xs) Source # | |
Defined in Jordan.FromJSON.Class Methods | |
SpecifiesToJSONOptions xs => SpecifiesToJSONOptions (OmitNothingFields ': xs) Source # | |
Defined in Jordan.ToJSON.Class Methods |
data KeepNothingFields Source #
Keep nothing fields.
Will have us omit null
when serializing Maybe types.
Constructors
KeepNothingFields |
Instances
SpecifiesFromJSONOptions xs => SpecifiesFromJSONOptions (KeepNothingFields ': xs) Source # | |
Defined in Jordan.FromJSON.Class Methods | |
SpecifiesToJSONOptions xs => SpecifiesToJSONOptions (KeepNothingFields ': xs) Source # | |
Defined in Jordan.ToJSON.Class Methods |
fullyQualifyName :: TypeRep -> Text Source #