{-# LANGUAGE UndecidableInstances #-}
module Data.Aeson.Deriving.EmptyObject where
import Data.Aeson
import Data.Kind (Type)
import GHC.Generics
newtype EmptyObject a = EmptyObject a
instance UnitLike (Rep a) => ToJSON (EmptyObject a) where
toJSON _ = object []
instance (Generic a, UnitLike (Rep a)) => FromJSON (EmptyObject a) where
parseJSON = withObject "object" $ \_hashmap ->
pure . EmptyObject $ to gPoint
class UnitLike (f :: Type -> Type) where
gPoint :: f a
instance UnitLike U1 where
gPoint = U1
instance UnitLike a => UnitLike (M1 C meta a) where
gPoint = M1 gPoint
instance UnitLike a => UnitLike (M1 D meta a) where
gPoint = M1 gPoint