autodocodec-0.2.0.3: Self-documenting encoder and decoder
Safe HaskellSafe-Inferred
LanguageHaskell2010

Autodocodec.Class

Synopsis

Documentation

class HasCodec value where Source #

A class for values which have a canonical codec.

There are no formal laws for this class. If you really want a law, it should be "Whomever uses the codec from your instance should not be surprised."

Minimal complete definition

codec

Methods

codec :: JSONCodec value Source #

A codec for a single value

See the sections on helper functions for implementing this for plenty of examples.

listCodecForStringCompatibility :: JSONCodec [value] Source #

A codec for a list of values

This is really only useful for cases like Char and String. We didn't call it listCodec so we could use that name for making a codec for a list of values from a single codec instead.

Instances

Instances details
HasCodec Value Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Void Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Int16 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Int32 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Int64 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Int8 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Word16 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Word32 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Word64 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Word8 Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Ordering Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Scientific Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Text Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Text Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Day Source # 
Instance details

Defined in Autodocodec.Class

HasCodec DiffTime Source # 
Instance details

Defined in Autodocodec.Class

HasCodec NominalDiffTime Source # 
Instance details

Defined in Autodocodec.Class

HasCodec UTCTime Source # 
Instance details

Defined in Autodocodec.Class

HasCodec LocalTime Source # 
Instance details

Defined in Autodocodec.Class

HasCodec TimeOfDay Source # 
Instance details

Defined in Autodocodec.Class

HasCodec ZonedTime Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Bool Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Char Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Int Source # 
Instance details

Defined in Autodocodec.Class

HasCodec Word Source # 
Instance details

Defined in Autodocodec.Class

HasCodec v => HasCodec (KeyMap v) Source # 
Instance details

Defined in Autodocodec.Class

(Ord a, HasCodec a) => HasCodec (Set a) Source # 
Instance details

Defined in Autodocodec.Class

HasCodec a => HasCodec (NonEmpty a) Source # 
Instance details

Defined in Autodocodec.Class

HasCodec a => HasCodec (Maybe a) Source # 
Instance details

Defined in Autodocodec.Class

HasCodec a => HasCodec [a] Source # 
Instance details

Defined in Autodocodec.Class

(HasCodec l, HasCodec r) => HasCodec (Either l r) Source # 
Instance details

Defined in Autodocodec.Class

(Ord k, FromJSONKey k, ToJSONKey k, HasCodec v) => HasCodec (Map k v) Source # 
Instance details

Defined in Autodocodec.Class

(Eq k, Hashable k, FromJSONKey k, ToJSONKey k, HasCodec v) => HasCodec (HashMap k v) Source # 
Instance details

Defined in Autodocodec.Class

class HasObjectCodec object where Source #

A class for values which have a canonical object codec.

There are no formal laws for this class. If you really want a law, it should be "Whomever uses the codec from your instance should not be surprised."

Methods

objectCodec :: JSONObjectCodec object Source #

A object codec for the value

See the sections on helper functions for implementing this for plenty of examples.

requiredField Source #

Arguments

:: HasCodec output 
=> Text

Key

-> Text

Documentation

-> ObjectCodec output output 

A required field

During decoding, the field must be in the object.

During encoding, the field will always be in the object.

See requiredFieldWith

requiredField' Source #

Arguments

:: HasCodec output 
=> Text

Key

-> ObjectCodec output output 

Like requiredField, but without documentation

optionalField Source #

Arguments

:: HasCodec output 
=> Text

Key

-> Text

Documentation

-> ObjectCodec (Maybe output) (Maybe output) 

An optional field

During decoding, the field may be in the object. Nothing will be parsed otherwise.

During encoding, the field will be in the object if it is not Nothing, and omitted otherwise.

See optionalFieldWith

optionalField' Source #

Arguments

:: HasCodec output 
=> Text

Key

-> ObjectCodec (Maybe output) (Maybe output) 

Like optionalField, but without documentation

optionalFieldWithDefault Source #

Arguments

:: HasCodec output 
=> Text

Key

-> output

Default value

-> Text

Documentation

-> ObjectCodec output output 

An optional field with a default value

During decoding, the field may be in the object. The default value will be parsed otherwise.

During encoding, the field will be in the object. The default value is ignored.

The shown version of the default value will appear in the documentation.

optionalFieldWithDefault' Source #

Arguments

:: HasCodec output 
=> Text

Key

-> output

Default value

-> ObjectCodec output output 

Like optionalFieldWithDefault, but without documentation

optionalFieldOrNull Source #

Arguments

:: forall output. HasCodec output 
=> Text

Key

-> Text

Documentation

-> ObjectCodec (Maybe output) (Maybe output) 

An optional, or null, field

During decoding, the field may be in the object. Nothing will be parsed if it is not. If the field is null, then it will be parsed as Nothing as well.

During encoding, the field will be in the object if it is not Nothing, and omitted otherwise.

optionalFieldOrNull' Source #

Arguments

:: forall output. HasCodec output 
=> Text

Key

-> ObjectCodec (Maybe output) (Maybe output) 

Like optionalFieldOrNull, but without documentation

optionalFieldWithOmittedDefault Source #

Arguments

:: (Eq output, HasCodec output) 
=> Text

Key

-> output

Default value

-> Text

Documentation

-> ObjectCodec output output 

optionalFieldWithOmittedDefault' Source #

Arguments

:: (Eq output, HasCodec output) 
=> Text

Key

-> output

Default value

-> ObjectCodec output output 

optionalFieldOrNullWithOmittedDefault Source #

Arguments

:: (Eq output, HasCodec output) 
=> Text

Key

-> output

Default value

-> Text

Documentation

-> ObjectCodec output output 

optionalFieldOrNullWithOmittedDefault' Source #

Arguments

:: (Eq output, HasCodec output) 
=> Text

Key

-> output

Default value

-> ObjectCodec output output