1
1
{-# LANGUAGE CPP #-}
2
2
{-# LANGUAGE DataKinds #-}
3
3
{-# LANGUAGE DefaultSignatures #-}
4
- {-# LANGUAGE InstanceSigs #-}
4
+ {-# LANGUAGE DerivingVia #-}
5
5
{-# LANGUAGE FlexibleContexts #-}
6
6
{-# LANGUAGE FlexibleInstances #-}
7
7
{-# LANGUAGE GADTs #-}
8
+ {-# LANGUAGE InstanceSigs #-}
8
9
{-# LANGUAGE MultiParamTypeClasses #-}
9
10
{-# LANGUAGE OverloadedStrings #-}
10
11
{-# LANGUAGE PolyKinds #-}
11
12
{-# LANGUAGE RecordWildCards #-}
12
13
{-# LANGUAGE ScopedTypeVariables #-}
14
+ {-# LANGUAGE StandaloneDeriving #-}
15
+ {-# LANGUAGE TupleSections #-}
13
16
{-# LANGUAGE TypeApplications #-}
14
17
{-# LANGUAGE TypeOperators #-}
15
- {-# LANGUAGE TupleSections #-}
16
18
{-# LANGUAGE UndecidableInstances #-}
17
19
{-# LANGUAGE ViewPatterns #-}
18
20
@@ -86,12 +88,12 @@ module Data.Aeson.Types.FromJSON
86
88
import Data.Aeson.Internal.Prelude
87
89
88
90
import Control.Monad (zipWithM , guard )
91
+ import Data.Aeson.Decoding.ByteString.Lazy
92
+ import Data.Aeson.Decoding.Conversion (unResult , toResultValue , lbsSpace )
89
93
import Data.Aeson.Internal.Functions (mapKey , mapKeyO )
90
94
import Data.Aeson.Internal.Scientific
91
95
import Data.Aeson.Types.Generic
92
96
import Data.Aeson.Types.Internal
93
- import Data.Aeson.Decoding.ByteString.Lazy
94
- import Data.Aeson.Decoding.Conversion (unResult , toResultValue , lbsSpace )
95
97
import Data.Bits (unsafeShiftR )
96
98
import Data.Fixed (Fixed , HasResolution (resolution ), Nano )
97
99
import Data.Functor.Compose (Compose (.. ))
@@ -100,6 +102,7 @@ import Data.Functor.Product (Product(..))
100
102
import Data.Functor.Sum (Sum (.. ))
101
103
import Data.Functor.These (These1 (.. ))
102
104
import Data.Hashable (Hashable (.. ))
105
+ import Data.Kind (Type )
103
106
import Data.List.NonEmpty (NonEmpty (.. ))
104
107
import Data.Ord (Down (.. ))
105
108
import Data.Ratio ((%) , Ratio )
@@ -1922,17 +1925,10 @@ instance (FromJSONKey a) => FromJSONKey (Solo a) where
1922
1925
1923
1926
instance FromJSON1 Identity where
1924
1927
liftParseJSON _ p _ a = coerce (p a)
1925
-
1926
1928
liftParseJSONList _ _ p a = coerce (p a)
1927
-
1928
1929
liftOmittedField = coerce
1929
1930
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 )
1936
1932
1937
1933
instance (FromJSONKey a ) => FromJSONKey (Identity a ) where
1938
1934
fromJSONKey = coerceFromJSONKeyFunction (fromJSONKey :: FromJSONKeyFunction a )
@@ -2313,114 +2309,42 @@ instance FromJSONKey Month where
2313
2309
-------------------------------------------------------------------------------
2314
2310
2315
2311
-- | @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
2320
2313
2321
2314
-- | @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 )
2324
2316
2325
2317
-------------------------------------------------------------------------------
2326
2318
-- base Monoid/Semigroup
2327
2319
-------------------------------------------------------------------------------
2328
2320
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 )
2331
2323
2332
- liftOmittedField = coerce
2324
+ deriving via Maybe instance FromJSON1 Monoid. First
2325
+ deriving via Maybe a instance FromJSON a => FromJSON (Monoid. First a )
2333
2326
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 )
2353
2329
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 )
2360
2332
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 )
2363
2335
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 )
2365
2338
2366
- omittedField = omittedField1
2339
+ deriving via Identity instance FromJSON1 Semigroup. Last
2340
+ deriving via (a :: Type ) instance FromJSON a => FromJSON (Semigroup. Last a )
2367
2341
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 )
2415
2344
2416
2345
#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 )
2424
2348
#endif
2425
2349
2426
2350
-------------------------------------------------------------------------------
0 commit comments