haskell / haskell/aeson

Could not deduce `RecordFromJSON'` and `RecordToPairs` in `aeson-2.2.0.0`

Open
#1,059 5 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Haskell
Stars
1.3k
Forks
336
Avg merge
3d 7h
Merged PRs (30d)
4

Description

I have the following code
```hs
{-# LANGUAGE DeriveGeneric #-}

import Data.Aeson
import GHC.Generics

data Item f a = Item { root :: a, children :: f a } deriving Generic1

instance FromJSON1 f => FromJSON1 (Item f) where liftParseJSON = genericLiftParseJSON defaultOptions
instance ToJSON1 f => ToJSON1 (Item f) where liftToJSON = genericLiftToJSON defaultOptions
instance (FromJSON1 f, FromJSON a) => FromJSON (Item f a) where parseJSON = parseJSON1
instance (ToJSON1 f, ToJSON a) => ToJSON (Item f a) where toJSON = toJSON1

data Content f a = Content { items :: f (Item f a) } deriving Generic1

instance (Functor f, FromJSON1 f) => FromJSON1 (Content f) where liftParseJSON = genericLiftParseJSON defaultOptions
instance (Functor f, ToJSON1 f) => ToJSON1 (Content f) where liftToJSON = genericLiftToJSON defaultOptions
instance (Functor f, FromJSON1 f, FromJSON a) => FromJSON (Content f a) where parseJSON = parseJSON1
instance (Functor f, ToJSON1 f, ToJSON a) => ToJSON (Content f a) where toJSON = toJSON1

main :: IO ()
main = return ()
```

With `aeson-2.1.2.1`, this code works perfectly fine. With `aeson-2.2.0.0`, I get the following errors:
```
Main.hs:15:82: error:
• Could not deduce (aeson-2.2.0.0:Data.Aeson.Types.FromJSON.RecordFromJSON'
One (f :.: Rec1 (Item f)))
arising from a use of ‘genericLiftParseJSON’
from the context: (Functor f, FromJSON1 f)
bound by the instance declaration at Main.hs:15:10-58
• In the expression: genericLiftParseJSON defaultOptions
In an equation for ‘liftParseJSON’:
liftParseJSON = genericLiftParseJSON defaultOptions
In the instance declaration for ‘FromJSON1 (Content f)’
|
15 | instance (Functor f, FromJSON1 f) => FromJSON1 (Content f) where liftParseJSON = genericLiftParseJSON defaultOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:16:10: error:
• Could not deduce (aeson-2.2.0.0:Data.Aeson.Types.ToJSON.RecordToPairs
(Data.Aeson.Encoding.Internal.Encoding' Value)
Series
One
(S1
('MetaSel
('Just "items")
'NoSourceUnpackedness
'NoSourceStrictness
'DecidedLazy)
(f :.: Rec1 (Item f))))
arising from a use of ‘aeson-2.2.0.0:Data.Aeson.Types.ToJSON.$dmliftToEncoding’
from the context: (Functor f, ToJSON1 f)
bound by the instance declaration at Main.hs:16:10-54
• In the expression:
aeson-2.2.0.0:Data.Aeson.Types.ToJSON.$dmliftToEncoding
@(Content f)
In an equation for ‘liftToEncoding’:
liftToEncoding
= aeson-2.2.0.0:Data.Aeson.Types.ToJSON.$dmliftToEncoding
@(Content f)
In the instance declaration for ‘ToJSON1 (Content f)’
|
16 | instance (Functor f, ToJSON1 f) => ToJSON1 (Content f) where liftToJSON = genericLiftToJSON defaultOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:16:75: error:
• Could not deduce (aeson-2.2.0.0:Data.Aeson.Types.ToJSON.RecordToPairs
Value
(dlist-1.0:Data.DList.Internal.DList
aeson-2.2.0.0:Data.Aeson.Types.Internal.Pair)
One
(S1
('MetaSel
('Just "items")
'NoSourceUnpackedness
'NoSourceStrictness
'DecidedLazy)
(f :.: Rec1 (Item f))))
arising from a use of ‘genericLiftToJSON’
from the context: (Functor f, ToJSON1 f)
bound by the instance declaration at Main.hs:16:10-54
• In the expression: genericLiftToJSON defaultOptions
In an equation for ‘liftToJSON’:
liftToJSON = genericLiftToJSON defaultOptions
In the instance declaration for ‘ToJSON1 (Content f)’
|
16 | instance (Functor f, ToJSON1 f) => ToJSON1 (Content f) where liftToJSON = genericLiftToJSON defaultOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

I looked at the changelog, and while there have apparently been some changes to the handling of Generics related to omitted fields, I did not find anything that would indicate that my situation should no longer work. Is this a regression or am I doing something wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.