aeson-gadt-th: Derivation of Aeson instances for GADTs

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

Warnings:

Template Haskell for generating ToJSON and FromJSON instances for GADTs. See README.md for examples.


[Skip to ReadMe]

Properties

Versions0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.1.2.1, 0.2.0.0
Change logNone available
Dependenciesaeson, aeson-gadt-th, base (>=4.8 && <4.13), dependent-sum, template-haskell, transformers [details]
LicenseBSD-3-Clause
Copyright2019 Obsidian Systems LLC
AuthorObsidian Systems LLC
Maintainermaintainer@obsidian.systems
CategoryJSON
Source repositoryhead: git clone git://github.com/obsidiansystems/aeson-gadt-th.git
Executablesreadme
UploadedThu Feb 14 23:37:02 UTC 2019 by abrar

Modules

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for aeson-gadt-th-0.1.2.1

[back to package description]

aeson-gadt-th

Provides Template Haskell expressions for deriving ToJSON and FromJSON instances for GADTs.

Example Usage:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

import Data.Aeson
import Data.Aeson.GADT.TH

data A :: * -> * where
  A_a :: A a
  A_b :: Int -> A ()

data B c :: * -> * where
  B_a :: c -> A a -> B c a
  B_x :: B c x

deriveJSONGADT ''A
deriveJSONGADT ''B

main :: IO ()
main = return ()

Encoding:

encode A_a
> "[\"A_a\",[]]"

Decoding:

When decoding a JSON-encoded GADT, the result will be wrapped using Data.Some.This.

case (decode $ encode A_a) :: Maybe (Some A) of
  Nothing -> error "Couldn't decode
  Just (This A_a) -> putStrLn "it worked"
  Just (This A_b) -> putStrLn "wat"
> it worked