I’m using aeson template haskell to generate instances for a record which I get from postgres.
I’m using the postgres citext which I unmarshal into the CI Text from case-insensitive package.
Unfortunately CI Text has no support for aeson. How can I manually write this instance for CI Text in my own codebase?
I’m new to haskell so it’s difficult to figure this out from only the hackage documentations.
The aeson documentation has a section on writing instances by hand, which is probably necessary in this case: Data.Aeson. In this case I think the instances would be pretty simple, something like:
instance (FromJSON a, FoldCase a) => FromJSON (CI a) where
parseJSON v = do
x <- parseJSON v
pure (mk x)
instance ToJSON a => ToJSON (CI a) where
toJSON x = toJSON (original x)
toEncoding x = toEncoding (original x)