I have a data type like this:
data A = A T.Text deriving (Generic, Show)
instance A.ToJSON A
If I use A.encode
to it:
A.encode $ A "foobar" -- "foobar"
Then I use singleTagConstructors
on it:
instance A.ToJSON A where
toEncoding a = A.genericToEncoding $ A.defaultOptions { A.tagSingleConstructors = True }
A.encode $ A "foobarquux" -- "{tag: A, contents: foobarquux}"
At some point I made another data type:
newtype Wrapper a = Wrapper
{ unWrap :: a
} deriving (Show)
instance A.ToJSON a => A.ToJSON (Wrapper a) where
toJSON w = A.object [ "wrapped" A..= unWrap w ]
Here's the part where I get confused:
A.encode $ Wrapper $ A "foobar" -- "{wrapped: foobar}"
How do I get the result to be like this?
"{wrapped: {tag: A, contents: foobarquux}}"