11{-# LANGUAGE CPP #-}
22{-# LANGUAGE DataKinds #-}
33{-# LANGUAGE DefaultSignatures #-}
4- {-# LANGUAGE InstanceSigs #-}
4+ {-# LANGUAGE DerivingVia #-}
55{-# LANGUAGE FlexibleContexts #-}
66{-# LANGUAGE FlexibleInstances #-}
77{-# LANGUAGE GADTs #-}
8+ {-# LANGUAGE InstanceSigs #-}
89{-# LANGUAGE MultiParamTypeClasses #-}
910{-# LANGUAGE OverloadedStrings #-}
1011{-# LANGUAGE PolyKinds #-}
1112{-# LANGUAGE RecordWildCards #-}
1213{-# LANGUAGE ScopedTypeVariables #-}
14+ {-# LANGUAGE StandaloneDeriving #-}
15+ {-# LANGUAGE TupleSections #-}
1316{-# LANGUAGE TypeApplications #-}
1417{-# LANGUAGE TypeOperators #-}
15- {-# LANGUAGE TupleSections #-}
1618{-# LANGUAGE UndecidableInstances #-}
1719{-# LANGUAGE ViewPatterns #-}
1820
@@ -86,12 +88,12 @@ module Data.Aeson.Types.FromJSON
8688import Data.Aeson.Internal.Prelude
8789
8890import Control.Monad (zipWithM , guard )
91+ import Data.Aeson.Decoding.ByteString.Lazy
92+ import Data.Aeson.Decoding.Conversion (unResult , toResultValue , lbsSpace )
8993import Data.Aeson.Internal.Functions (mapKey , mapKeyO )
9094import Data.Aeson.Internal.Scientific
9195import Data.Aeson.Types.Generic
9296import Data.Aeson.Types.Internal
93- import Data.Aeson.Decoding.ByteString.Lazy
94- import Data.Aeson.Decoding.Conversion (unResult , toResultValue , lbsSpace )
9597import Data.Bits (unsafeShiftR )
9698import Data.Fixed (Fixed , HasResolution (resolution ), Nano )
9799import Data.Functor.Compose (Compose (.. ))
@@ -100,6 +102,7 @@ import Data.Functor.Product (Product(..))
100102import Data.Functor.Sum (Sum (.. ))
101103import Data.Functor.These (These1 (.. ))
102104import Data.Hashable (Hashable (.. ))
105+ import Data.Kind (Type )
103106import Data.List.NonEmpty (NonEmpty (.. ))
104107import Data.Ord (Down (.. ))
105108import Data.Ratio ((%) , Ratio )
@@ -1922,17 +1925,10 @@ instance (FromJSONKey a) => FromJSONKey (Solo a) where
19221925
19231926instance FromJSON1 Identity where
19241927 liftParseJSON _ p _ a = coerce (p a)
1925-
19261928 liftParseJSONList _ _ p a = coerce (p a)
1927-
19281929 liftOmittedField = coerce
19291930
1930- instance (FromJSON a ) => FromJSON (Identity a ) where
1931- parseJSON = parseJSON1
1932-
1933- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
1934-
1935- omittedField = coerce (omittedField @ a )
1931+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Identity a )
19361932
19371933instance (FromJSONKey a ) => FromJSONKey (Identity a ) where
19381934 fromJSONKey = coerceFromJSONKeyFunction (fromJSONKey :: FromJSONKeyFunction a )
@@ -2313,114 +2309,42 @@ instance FromJSONKey Month where
23132309-------------------------------------------------------------------------------
23142310
23152311-- | @since 2.2.0.0
2316- instance FromJSON1 Down where
2317- liftParseJSON _ p _ = coerce p
2318-
2319- liftOmittedField = coerce
2312+ deriving via Identity instance FromJSON1 Down
23202313
23212314-- | @since 2.2.0.0
2322- instance FromJSON a => FromJSON (Down a ) where
2323- parseJSON = parseJSON1
2315+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Down a )
23242316
23252317-------------------------------------------------------------------------------
23262318-- base Monoid/Semigroup
23272319-------------------------------------------------------------------------------
23282320
2329- instance FromJSON1 Monoid. Dual where
2330- liftParseJSON _ p _ = coerce p
2321+ deriving via Identity instance FromJSON1 Monoid. Dual
2322+ deriving via ( a :: Type ) instance FromJSON a => FromJSON ( Monoid. Dual a )
23312323
2332- liftOmittedField = coerce
2324+ deriving via Maybe instance FromJSON1 Monoid. First
2325+ deriving via Maybe a instance FromJSON a => FromJSON (Monoid. First a )
23332326
2334- instance FromJSON a => FromJSON (Monoid. Dual a ) where
2335- parseJSON = parseJSON1
2336-
2337-
2338- instance FromJSON1 Monoid. First where
2339- liftParseJSON o = coerce (liftParseJSON @ Maybe o)
2340- liftOmittedField _ = Just (Monoid. First Nothing )
2341-
2342- instance FromJSON a => FromJSON (Monoid. First a ) where
2343- parseJSON = parseJSON1
2344- omittedField = omittedField1
2345-
2346- instance FromJSON1 Monoid. Last where
2347- liftParseJSON o = coerce (liftParseJSON @ Maybe o)
2348- liftOmittedField _ = Just (Monoid. Last Nothing )
2349-
2350- instance FromJSON a => FromJSON (Monoid. Last a ) where
2351- parseJSON = parseJSON1
2352- omittedField = omittedField1
2327+ deriving via Maybe instance FromJSON1 Monoid. Last
2328+ deriving via Maybe a instance FromJSON a => FromJSON (Monoid. Last a )
23532329
2354- instance FromJSON1 Semigroup. Min where
2355- liftParseJSON _ p _ a = coerce (p a)
2356-
2357- liftParseJSONList _ _ p a = coerce (p a)
2358-
2359- liftOmittedField = coerce
2330+ deriving via Identity instance FromJSON1 Semigroup. Min
2331+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Semigroup. Min a )
23602332
2361- instance ( FromJSON a ) => FromJSON ( Semigroup. Min a ) where
2362- parseJSON = parseJSON1
2333+ deriving via Identity instance FromJSON1 Semigroup. Max
2334+ deriving via ( a :: Type ) instance FromJSON a => FromJSON ( Semigroup. Max a )
23632335
2364- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
2336+ deriving via Identity instance FromJSON1 Semigroup. First
2337+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Semigroup. First a )
23652338
2366- omittedField = omittedField1
2339+ deriving via Identity instance FromJSON1 Semigroup. Last
2340+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Semigroup. Last a )
23672341
2368- instance FromJSON1 Semigroup. Max where
2369- liftParseJSON _ p _ a = coerce (p a)
2370-
2371- liftParseJSONList _ _ p a = coerce (p a)
2372- liftOmittedField = coerce
2373-
2374- instance (FromJSON a ) => FromJSON (Semigroup. Max a ) where
2375- parseJSON = parseJSON1
2376-
2377- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
2378- omittedField = omittedField1
2379-
2380- instance FromJSON1 Semigroup. First where
2381- liftParseJSON _ p _ a = coerce (p a)
2382-
2383- liftParseJSONList _ _ p a = coerce (p a)
2384- liftOmittedField = coerce
2385-
2386- instance (FromJSON a ) => FromJSON (Semigroup. First a ) where
2387- parseJSON = parseJSON1
2388-
2389- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
2390-
2391-
2392- instance FromJSON1 Semigroup. Last where
2393- liftParseJSON _ p _ a = coerce (p a)
2394-
2395- liftParseJSONList _ _ p a = coerce (p a)
2396- liftOmittedField = coerce
2397-
2398- instance (FromJSON a ) => FromJSON (Semigroup. Last a ) where
2399- parseJSON = parseJSON1
2400-
2401- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
2402- omittedField = omittedField1
2403-
2404- instance FromJSON1 Semigroup. WrappedMonoid where
2405- liftParseJSON _ p _ a = coerce (p a)
2406-
2407- liftParseJSONList _ _ p a = coerce (p a)
2408- liftOmittedField = coerce
2409-
2410- instance (FromJSON a ) => FromJSON (Semigroup. WrappedMonoid a ) where
2411- parseJSON = parseJSON1
2412-
2413- parseJSONList = liftParseJSONList omittedField parseJSON parseJSONList
2414- omittedField = omittedField1
2342+ deriving via Identity instance FromJSON1 Semigroup. WrappedMonoid
2343+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Semigroup. WrappedMonoid a )
24152344
24162345#if !MIN_VERSION_base(4,16,0)
2417- instance FromJSON1 Semigroup. Option where
2418- liftParseJSON o = coerce (liftParseJSON @ Maybe o)
2419- liftOmittedField _ = Just (Semigroup. Option Nothing )
2420-
2421- instance FromJSON a => FromJSON (Semigroup. Option a ) where
2422- parseJSON = parseJSON1
2423- omittedField = omittedField1
2346+ deriving via Maybe instance FromJSON1 Semigroup. Option
2347+ deriving via Maybe a instance FromJSON a => FromJSON (Semigroup. Option a )
24242348#endif
24252349
24262350-------------------------------------------------------------------------------
0 commit comments