foliage/app/Foliage/Utils/Aeson.hs
Andrea Bedini eaff46e671 Whitespace
2023-03-03 08:15:19 +08:00

25 lines
677 B
Haskell

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances #-}
module Foliage.Utils.Aeson where
import Data.Aeson
import Data.Coerce
import GHC.Generics
newtype MyAesonEncoding a = MyAesonEncoding a
deriving (Generic)
myOptions :: Options
myOptions =
defaultOptions
{ sumEncoding = ObjectWithSingleField,
omitNothingFields = True
}
instance (Generic a, GToJSON' Value Zero (Rep a), GToJSON' Encoding Zero (Rep a)) => ToJSON (MyAesonEncoding a) where
toJSON = coerce (genericToJSON myOptions :: a -> Value)
toEncoding = coerce (genericToEncoding myOptions :: a -> Encoding)