@@ -0,0 +1,2099 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
3+{-# LANGUAGE DefaultSignatures #-}
4+{-# LANGUAGE FlexibleContexts #-}
5+{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE GADTs #-}
7+{-# LANGUAGE MultiParamTypeClasses #-}
8+{-# LANGUAGE NamedFieldPuns #-}
9+{-# LANGUAGE OverloadedStrings #-}
10+{-# LANGUAGE PatternGuards #-}
11+{-# LANGUAGE RecordWildCards #-}
12+{-# LANGUAGE ScopedTypeVariables #-}
13+{-# LANGUAGE TypeOperators #-}
14+{-# LANGUAGE TypeSynonymInstances #-}
15+{-# LANGUAGE UndecidableInstances #-}
16+
17+#if __GLASGOW_HASKELL__ >= 706
18+{-# LANGUAGE PolyKinds #-}
19+#endif
20+
21+#include "overlapping-compat.h"
22+
23+-- TODO: Drop this when we remove support for Data.Attoparsec.Number
24+{-# OPTIONS_GHC -fno-warn-deprecations #-}
25+
26+module Data.Aeson.Types.ToJSON (
27+ -- * Core JSON classes
28+ ToJSON(..)
29+ -- * Liftings to unary and binary type constructors
30+ , ToJSON1(..)
31+ , toJSON1
32+ , toEncoding1
33+ , ToJSON2(..)
34+ , toJSON2
35+ , toEncoding2
36+ -- * Generic JSON classes
37+ , GToJSON(..)
38+ , GToEncoding(..)
39+ , genericToJSON
40+ , genericToEncoding
41+ -- * Classes and types for map keys
42+ , ToJSONKey(..)
43+ , ToJSONKeyFunction(..)
44+ , contramapToJSONKeyFunction
45+ -- * Object key-value pairs
46+ , KeyValue(..)
47+ -- * Functions needed for documentation
48+ -- * Encoding functions
49+ , listEncoding
50+ , listValue
51+ ) where
52+
53+import Prelude ()
54+import Prelude.Compat
55+
56+import Data.Aeson.Encoding.Internal (Encoding (..), Series, dict, emptyArray_,
57+ tuple, (>*<))
58+import Data.Aeson.Functions (mapHashKeyVal, mapKeyVal)
59+import Data.Aeson.Types.Generic
60+import Data.Aeson.Types.Internal
61+
62+import qualified Data.Aeson.Encode.Builder as EB
63+import qualified Data.Aeson.Encoding.Internal as E
64+
65+import Control.Applicative (Const (..))
66+import Control.Monad.ST (ST)
67+import Data.Attoparsec.Number (Number (..))
68+import Data.Bits (unsafeShiftR)
69+import Data.DList (DList)
70+import Data.Fixed (Fixed, HasResolution)
71+import Data.Foldable (toList)
72+import Data.Functor.Identity (Identity (..))
73+import Data.Int (Int16, Int32, Int64, Int8)
74+import Data.List (intersperse)
75+import Data.List.NonEmpty (NonEmpty (..))
76+import Data.Monoid (Dual (..), First (..), Last (..), (<>))
77+import Data.Proxy (Proxy (..))
78+import Data.Ratio (Ratio, denominator, numerator)
79+import Data.Scientific (Scientific)
80+import Data.Tagged (Tagged (..))
81+import Data.Text (Text, pack)
82+import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay,
83+ UTCTime, ZonedTime)
84+import Data.Time.Format (FormatTime, formatTime)
85+import Data.Time.Locale.Compat (defaultTimeLocale)
86+import Data.Vector (Vector)
87+import Data.Version (Version, showVersion)
88+import Data.Word (Word16, Word32, Word64, Word8)
89+import Foreign.Storable (Storable)
90+import GHC.Generics
91+import Numeric.Natural (Natural)
92+
93+import qualified Data.ByteString.Builder as B
94+import qualified Data.ByteString.Lazy as L
95+import qualified Data.DList as DList
96+import qualified Data.HashMap.Strict as H
97+import qualified Data.HashSet as HashSet
98+import qualified Data.IntMap as IntMap
99+import qualified Data.IntSet as IntSet
100+import qualified Data.List.NonEmpty as NE
101+import qualified Data.Map as M
102+import qualified Data.Scientific as Scientific
103+import qualified Data.Sequence as Seq
104+import qualified Data.Set as Set
105+import qualified Data.Text as T
106+import qualified Data.Text.Encoding as T
107+import qualified Data.Text.Lazy as LT
108+import qualified Data.Text.Lazy.Builder as LTB
109+import qualified Data.Text.Lazy.Builder.Int as LTBI
110+import qualified Data.Tree as Tree
111+import qualified Data.Vector as V
112+import qualified Data.Vector.Generic as VG
113+import qualified Data.Vector.Mutable as VM
114+import qualified Data.Vector.Primitive as VP
115+import qualified Data.Vector.Storable as VS
116+import qualified Data.Vector.Unboxed as VU
117+
118+builder :: ToJSON a => a -> B.Builder
119+builder = fromEncoding . toEncoding
120+
121+toJSONPair :: (a -> Value) -> (b -> Value) -> (a, b) -> Value
122+toJSONPair keySerialiser valSerializer (a, b) = Array $ V.create $ do
123+ mv <- VM.unsafeNew 2
124+ VM.unsafeWrite mv 0 (keySerialiser a)
125+ VM.unsafeWrite mv 1 (valSerializer b)
126+ return mv
127+{-# INLINE toJSONPair #-}
128+
129+realFloatToJSON :: RealFloat a => a -> Value
130+realFloatToJSON d
131+ | isNaN d || isInfinite d = Null
132+ | otherwise = Number $ Scientific.fromFloatDigits d
133+{-# INLINE realFloatToJSON #-}
134+
135+realFloatToEncoding :: RealFloat a => a -> Encoding
136+realFloatToEncoding d
137+ | isNaN d || isInfinite d = Encoding EB.null_
138+ | otherwise = toEncoding (Scientific.fromFloatDigits d)
139+{-# INLINE realFloatToEncoding #-}
140+-------------------------------------------------------------------------------
141+-- Generics
142+-------------------------------------------------------------------------------
143+
144+-- | Class of generic representation types ('Rep') that can be converted to
145+-- JSON.
146+class GToJSON f where
147+ -- | This method (applied to 'defaultOptions') is used as the
148+ -- default generic implementation of 'toJSON'.
149+ gToJSON :: Options -> f a -> Value
150+
151+-- | Class of generic representation types ('Rep') that can be converted to
152+-- a JSON 'Encoding'.
153+class GToEncoding f where
154+ -- | This method (applied to 'defaultOptions') can be used as the
155+ -- default generic implementation of 'toEncoding'.
156+ gToEncoding :: Options -> f a -> Encoding
157+
158+
159+-- | A configurable generic JSON creator. This function applied to
160+-- 'defaultOptions' is used as the default for 'toJSON' when the type
161+-- is an instance of 'Generic'.
162+genericToJSON :: (Generic a, GToJSON (Rep a)) => Options -> a -> Value
163+genericToJSON opts = gToJSON opts . from
164+
165+-- | A configurable generic JSON encoder. This function applied to
166+-- 'defaultOptions' is used as the default for 'toEncoding' when the type
167+-- is an instance of 'Generic'.
168+genericToEncoding :: (Generic a, GToEncoding (Rep a)) => Options -> a -> Encoding
169+genericToEncoding opts = gToEncoding opts . from
170+
171+-------------------------------------------------------------------------------
172+-- Class
173+-------------------------------------------------------------------------------
174+
175+-- | A type that can be converted to JSON.
176+--
177+-- An example type and instance:
178+--
179+-- @
180+-- \-- Allow ourselves to write 'Text' literals.
181+-- {-\# LANGUAGE OverloadedStrings #-}
182+--
183+-- data Coord = Coord { x :: Double, y :: Double }
184+--
185+-- instance ToJSON Coord where
186+-- toJSON (Coord x y) = 'object' [\"x\" '.=' x, \"y\" '.=' y]
187+--
188+-- toEncoding (Coord x y) = 'pairs' (\"x\" '.=' x '<>' \"y\" '.=' y)
189+-- @
190+--
191+-- Instead of manually writing your 'ToJSON' instance, there are two options
192+-- to do it automatically:
193+--
194+-- * "Data.Aeson.TH" provides Template Haskell functions which will derive an
195+-- instance at compile time. The generated instance is optimized for your type
196+-- so will probably be more efficient than the following two options:
197+--
198+-- * The compiler can provide a default generic implementation for
199+-- 'toJSON'.
200+--
201+-- To use the second, simply add a @deriving 'Generic'@ clause to your
202+-- datatype and declare a 'ToJSON' instance for your datatype without giving
203+-- definitions for 'toJSON' or 'toEncoding'.
204+--
205+-- For example, the previous example can be simplified to a more
206+-- minimal instance:
207+--
208+-- @
209+-- {-\# LANGUAGE DeriveGeneric \#-}
210+--
211+-- import "GHC.Generics"
212+--
213+-- data Coord = Coord { x :: Double, y :: Double } deriving 'Generic'
214+--
215+-- instance ToJSON Coord where
216+-- toEncoding = 'genericToEncoding' 'defaultOptions'
217+-- @
218+--
219+-- Why do we provide an implementation for 'toEncoding' here? The
220+-- 'toEncoding' function is a relatively new addition to this class.
221+-- To allow users of older versions of this library to upgrade without
222+-- having to edit all of their instances or encounter surprising
223+-- incompatibilities, the default implementation of 'toEncoding' uses
224+-- 'toJSON'. This produces correct results, but since it performs an
225+-- intermediate conversion to a 'Value', it will be less efficient
226+-- than directly emitting an 'Encoding'. Our one-liner definition of
227+-- 'toEncoding' above bypasses the intermediate 'Value'.
228+--
229+-- If @DefaultSignatures@ doesn't give exactly the results you want,
230+-- you can customize the generic encoding with only a tiny amount of
231+-- effort, using 'genericToJSON' and 'genericToEncoding' with your
232+-- preferred 'Options':
233+--
234+-- @
235+-- instance ToJSON Coord where
236+-- toJSON = 'genericToJSON' 'defaultOptions'
237+-- toEncoding = 'genericToEncoding' 'defaultOptions'
238+-- @
239+class ToJSON a where
240+ -- | Convert a Haskell value to a JSON-friendly intermediate type.
241+ toJSON :: a -> Value
242+
243+ default toJSON :: (Generic a, GToJSON (Rep a)) => a -> Value
244+ toJSON = genericToJSON defaultOptions
245+
246+ -- | Encode a Haskell value as JSON.
247+ --
248+ -- The default implementation of this method creates an
249+ -- intermediate 'Value' using 'toJSON'. This provides
250+ -- source-level compatibility for people upgrading from older
251+ -- versions of this library, but obviously offers no performance
252+ -- advantage.
253+ --
254+ -- To benefit from direct encoding, you /must/ provide an
255+ -- implementation for this method. The easiest way to do so is by
256+ -- having your types implement 'Generic' using the @DeriveGeneric@
257+ -- extension, and then have GHC generate a method body as follows.
258+ --
259+ -- @
260+ -- instance ToJSON Coord where
261+ -- toEncoding = 'genericToEncoding' 'defaultOptions'
262+ -- @
263+
264+ toEncoding :: a -> Encoding
265+ toEncoding = E.Encoding . EB.encodeToBuilder . toJSON
266+ {-# INLINE toEncoding #-}
267+
268+ toJSONList :: [a] -> Value
269+ toJSONList = listValue toJSON
270+ {-# INLINE toJSONList #-}
271+
272+ toEncodingList :: [a] -> Encoding
273+ toEncodingList = listEncoding toEncoding
274+ {-# INLINE toEncodingList #-}
275+
276+-------------------------------------------------------------------------------
277+-- Object key-value pairs
278+-------------------------------------------------------------------------------
279+
280+-- | A key-value pair for encoding a JSON object.
281+class KeyValue kv where
282+ (.=) :: ToJSON v => Text -> v -> kv
283+ infixr 8 .=
284+
285+instance KeyValue Series where
286+ name .= value = E.Value $ E.text name <> E.colon <> toEncoding value
287+ {-# INLINE (.=) #-}
288+
289+instance KeyValue Pair where
290+ name .= value = (name, toJSON value)
291+ {-# INLINE (.=) #-}
292+
293+-------------------------------------------------------------------------------
294+-- Classes and types for map keys
295+-------------------------------------------------------------------------------
296+
297+class ToJSONKey a where
298+ toJSONKey :: ToJSONKeyFunction a
299+ default toJSONKey :: ToJSON a => ToJSONKeyFunction a
300+ toJSONKey = ToJSONKeyValue (toJSON, toEncoding)
301+ toJSONKeyList :: ToJSONKeyFunction [a]
302+ default toJSONKeyList :: ToJSON a => ToJSONKeyFunction [a]
303+ toJSONKeyList = ToJSONKeyValue (toJSON, toEncoding)
304+
305+data ToJSONKeyFunction a
306+ = ToJSONKeyText (a -> Text, a -> Encoding)
307+ | ToJSONKeyValue (a -> Value, a -> Encoding)
308+
309+contramapToJSONKeyFunction :: (b -> a) -> ToJSONKeyFunction a -> ToJSONKeyFunction b
310+contramapToJSONKeyFunction h x = case x of
311+ ToJSONKeyText (f,g) -> ToJSONKeyText (f . h, g . h)
312+ ToJSONKeyValue (f,g) -> ToJSONKeyValue (f . h, g . h)
313+
314+-------------------------------------------------------------------------------
315+-- Lifings of FromJSON and ToJSON to unary and binary type constructors
316+-------------------------------------------------------------------------------
317+
318+-- | Lifting of the 'ToJSON' class to unary type constructors.
319+class ToJSON1 f where
320+ liftToJSON :: (a -> Value) -> ([a] -> Value) -> f a -> Value
321+ liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [f a] -> Value
322+ liftToJSONList f g = listValue (liftToJSON f g)
323+
324+ -- | Unfortunately there cannot be a default implementation of 'liftToEncoding'.
325+ liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding
326+ liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [f a] -> Encoding
327+ liftToEncodingList f g = listEncoding (liftToEncoding f g)
328+
329+-- | Lift the standard 'toJSON' function through the type constructor.
330+toJSON1 :: (ToJSON1 f, ToJSON a) => f a -> Value
331+toJSON1 = liftToJSON toJSON toJSONList
332+{-# INLINE toJSON1 #-}
333+
334+-- | Lift the standard 'toEncoding' function through the type constructor.
335+toEncoding1 :: (ToJSON1 f, ToJSON a) => f a -> Encoding
336+toEncoding1 = liftToEncoding toEncoding toEncodingList
337+{-# INLINE toEncoding1 #-}
338+
339+
340+-- | Lifting of the 'ToJSON' class to binary type constructors.
341+class ToJSON2 f where
342+ liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> f a b -> Value
343+ liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [f a b] -> Value
344+ liftToJSONList2 fa ga fb gb = listValue (liftToJSON2 fa ga fb gb)
345+
346+ liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> f a b -> Encoding
347+ liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [f a b] -> Encoding
348+ liftToEncodingList2 fa ga fb gb = listEncoding (liftToEncoding2 fa ga fb gb)
349+
350+-- | Lift the standard 'toJSON' function through the type constructor.
351+toJSON2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Value
352+toJSON2 = liftToJSON2 toJSON toJSONList toJSON toJSONList
353+{-# INLINE toJSON2 #-}
354+
355+-- | Lift the standard 'toEncoding' function through the type constructor.
356+toEncoding2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Encoding
357+toEncoding2 = liftToEncoding2 toEncoding toEncodingList toEncoding toEncodingList
358+{-# INLINE toEncoding2 #-}
359+
360+-------------------------------------------------------------------------------
361+-- Encoding functions
362+-------------------------------------------------------------------------------
363+
364+listEncoding :: (a -> Encoding) -> [a] -> Encoding
365+listEncoding = E.list
366+
367+listValue :: (a -> Value) -> [a] -> Value
368+listValue f = Array . V.fromList . map f
369+{-# INLINE listValue #-}
370+
371+-------------------------------------------------------------------------------
372+-- [] instances
373+-------------------------------------------------------------------------------
374+
375+-- These are needed for key-class default definitions
376+
377+instance ToJSON1 [] where
378+ liftToJSON _ to' = to'
379+ {-# INLINE liftToJSON #-}
380+
381+ liftToEncoding _ to' = to'
382+ {-# INLINE liftToEncoding #-}
383+
384+instance (ToJSON a) => ToJSON [a] where
385+ toJSON = toJSON1
386+ {-# INLINE toJSON #-}
387+
388+ toEncoding = toEncoding1
389+ {-# INLINE toEncoding #-}
390+
391+-------------------------------------------------------------------------------
392+-- Generic toJSON / toEncoding
393+-------------------------------------------------------------------------------
394+
395+--------------------------------------------------------------------------------
396+-- Generic toJSON
397+
398+instance OVERLAPPABLE_ (GToJSON a) => GToJSON (M1 i c a) where
399+ -- Meta-information, which is not handled elsewhere, is ignored:
400+ gToJSON opts = gToJSON opts . unM1
401+
402+instance (ToJSON a) => GToJSON (K1 i a) where
403+ -- Constant values are encoded using their ToJSON instance:
404+ gToJSON _opts = toJSON . unK1
405+
406+instance GToJSON U1 where
407+ -- Empty constructors are encoded to an empty array:
408+ gToJSON _opts _ = emptyArray
409+
410+instance (ConsToJSON a) => GToJSON (C1 c a) where
411+ -- Constructors need to be encoded differently depending on whether they're
412+ -- a record or not. This distinction is made by 'consToJSON':
413+ gToJSON opts = consToJSON opts . unM1
414+
415+instance ( WriteProduct a, WriteProduct b
416+ , ProductSize a, ProductSize b ) => GToJSON (a :*: b) where
417+ -- Products are encoded to an array. Here we allocate a mutable vector of
418+ -- the same size as the product and write the product's elements to it using
419+ -- 'writeProduct':
420+ gToJSON opts p =
421+ Array $ V.create $ do
422+ mv <- VM.unsafeNew lenProduct
423+ writeProduct opts mv 0 lenProduct p
424+ return mv
425+ where
426+ lenProduct = (unTagged2 :: Tagged2 (a :*: b) Int -> Int)
427+ productSize
428+
429+instance ( AllNullary (a :+: b) allNullary
430+ , SumToJSON (a :+: b) allNullary ) => GToJSON (a :+: b) where
431+ -- If all constructors of a sum datatype are nullary and the
432+ -- 'allNullaryToStringTag' option is set they are encoded to
433+ -- strings. This distinction is made by 'sumToJSON':
434+ gToJSON opts = (unTagged :: Tagged allNullary Value -> Value)
435+ . sumToJSON opts
436+
437+--------------------------------------------------------------------------------
438+-- Generic toEncoding
439+
440+instance OVERLAPPABLE_ (GToEncoding a) => GToEncoding (M1 i c a) where
441+ -- Meta-information, which is not handled elsewhere, is ignored:
442+ gToEncoding opts = gToEncoding opts . unM1
443+
444+instance (ToJSON a) => GToEncoding (K1 i a) where
445+ -- Constant values are encoded using their ToJSON instance:
446+ gToEncoding _opts = toEncoding . unK1
447+
448+instance GToEncoding U1 where
449+ -- Empty constructors are encoded to an empty array:
450+ gToEncoding _opts _ = E.emptyArray_
451+
452+instance (ConsToEncoding a) => GToEncoding (C1 c a) where
453+ -- Constructors need to be encoded differently depending on whether they're
454+ -- a record or not. This distinction is made by 'consToEncoding':
455+ gToEncoding opts = consToEncoding opts . unM1
456+
457+instance ( EncodeProduct a, EncodeProduct b ) => GToEncoding (a :*: b) where
458+ -- Products are encoded to an array. Here we allocate a mutable vector of
459+ -- the same size as the product and write the product's elements to it using
460+ -- 'encodeProduct':
461+ gToEncoding opts p = E.tuple $ encodeProduct opts p
462+
463+instance ( AllNullary (a :+: b) allNullary
464+ , SumToEncoding (a :+: b) allNullary ) => GToEncoding (a :+: b) where
465+ -- If all constructors of a sum datatype are nullary and the
466+ -- 'allNullaryToStringTag' option is set they are encoded to
467+ -- strings. This distinction is made by 'sumToEncoding':
468+ gToEncoding opts
469+ = (unTagged :: Tagged allNullary Encoding -> Encoding)
470+ . sumToEncoding opts
471+
472+--------------------------------------------------------------------------------
473+
474+class SumToJSON f allNullary where
475+ sumToJSON :: Options -> f a -> Tagged allNullary Value
476+
477+instance ( GetConName f
478+ , TaggedObjectPairs f
479+ , ObjectWithSingleFieldObj f
480+ , TwoElemArrayObj f ) => SumToJSON f True where
481+ sumToJSON opts
482+ | allNullaryToStringTag opts = Tagged . String . pack
483+ . constructorTagModifier opts . getConName
484+ | otherwise = Tagged . nonAllNullarySumToJSON opts
485+
486+instance ( TwoElemArrayObj f
487+ , TaggedObjectPairs f
488+ , ObjectWithSingleFieldObj f ) => SumToJSON f False where
489+ sumToJSON opts = Tagged . nonAllNullarySumToJSON opts
490+
491+nonAllNullarySumToJSON :: ( TwoElemArrayObj f
492+ , TaggedObjectPairs f
493+ , ObjectWithSingleFieldObj f
494+ ) => Options -> f a -> Value
495+nonAllNullarySumToJSON opts =
496+ case sumEncoding opts of
497+ TaggedObject{..} ->
498+ object . taggedObjectPairs opts tagFieldName contentsFieldName
499+ ObjectWithSingleField -> Object . objectWithSingleFieldObj opts
500+ TwoElemArray -> Array . twoElemArrayObj opts
501+
502+--------------------------------------------------------------------------------
503+
504+class SumToEncoding f allNullary where
505+ sumToEncoding :: Options -> f a -> Tagged allNullary Encoding
506+
507+instance ( GetConName f
508+ , TaggedObjectEnc f
509+ , ObjectWithSingleFieldEnc f
510+ , TwoElemArrayEnc f ) => SumToEncoding f True where
511+ sumToEncoding opts
512+ | allNullaryToStringTag opts = Tagged . toEncoding .
513+ constructorTagModifier opts . getConName
514+ | otherwise = Tagged . nonAllNullarySumToEncoding opts
515+
516+instance ( TwoElemArrayEnc f
517+ , TaggedObjectEnc f
518+ , ObjectWithSingleFieldEnc f ) => SumToEncoding f False where
519+ sumToEncoding opts = Tagged . nonAllNullarySumToEncoding opts
520+
521+nonAllNullarySumToEncoding :: ( TwoElemArrayEnc f
522+ , TaggedObjectEnc f
523+ , ObjectWithSingleFieldEnc f
524+ ) => Options -> f a -> Encoding
525+nonAllNullarySumToEncoding opts =
526+ case sumEncoding opts of
527+ TaggedObject{..} ->
528+ taggedObjectEnc opts tagFieldName contentsFieldName
529+ ObjectWithSingleField -> objectWithSingleFieldEnc opts
530+ TwoElemArray -> twoElemArrayEnc opts
531+
532+--------------------------------------------------------------------------------
533+
534+class TaggedObjectPairs f where
535+ taggedObjectPairs :: Options -> String -> String -> f a -> [Pair]
536+
537+instance ( TaggedObjectPairs a
538+ , TaggedObjectPairs b ) => TaggedObjectPairs (a :+: b) where
539+ taggedObjectPairs opts tagFieldName contentsFieldName (L1 x) =
540+ taggedObjectPairs opts tagFieldName contentsFieldName x
541+ taggedObjectPairs opts tagFieldName contentsFieldName (R1 x) =
542+ taggedObjectPairs opts tagFieldName contentsFieldName x
543+
544+instance ( IsRecord a isRecord
545+ , TaggedObjectPairs' a isRecord
546+ , Constructor c ) => TaggedObjectPairs (C1 c a) where
547+ taggedObjectPairs opts tagFieldName contentsFieldName =
548+ (pack tagFieldName .= constructorTagModifier opts
549+ (conName (undefined :: t c a p)) :) .
550+ (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
551+ taggedObjectPairs' opts contentsFieldName . unM1
552+
553+class TaggedObjectPairs' f isRecord where
554+ taggedObjectPairs' :: Options -> String -> f a -> Tagged isRecord [Pair]
555+
556+instance OVERLAPPING_ TaggedObjectPairs' U1 False where
557+ taggedObjectPairs' _ _ _ = Tagged []
558+
559+instance (RecordToPairs f) => TaggedObjectPairs' f True where
560+ taggedObjectPairs' opts _ = Tagged . toList . recordToPairs opts
561+
562+instance (GToJSON f) => TaggedObjectPairs' f False where
563+ taggedObjectPairs' opts contentsFieldName =
564+ Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts
565+
566+--------------------------------------------------------------------------------
567+
568+class TaggedObjectEnc f where
569+ taggedObjectEnc :: Options -> String -> String -> f a -> Encoding
570+
571+instance ( TaggedObjectEnc a
572+ , TaggedObjectEnc b ) => TaggedObjectEnc (a :+: b) where
573+ taggedObjectEnc opts tagFieldName contentsFieldName (L1 x) =
574+ taggedObjectEnc opts tagFieldName contentsFieldName x
575+ taggedObjectEnc opts tagFieldName contentsFieldName (R1 x) =
576+ taggedObjectEnc opts tagFieldName contentsFieldName x
577+
578+instance ( IsRecord a isRecord
579+ , TaggedObjectEnc' a isRecord
580+ , Constructor c ) => TaggedObjectEnc (C1 c a) where
581+ taggedObjectEnc opts tagFieldName contentsFieldName v =
582+ E.openCurly <>
583+ (toEncoding tagFieldName <>
584+ E.colon <>
585+ toEncoding (constructorTagModifier opts (conName (undefined :: t c a p)))) <>
586+ ((unTagged :: Tagged isRecord Encoding -> Encoding) .
587+ taggedObjectEnc' opts contentsFieldName . unM1 $ v) <>
588+ E.closeCurly
589+
590+class TaggedObjectEnc' f isRecord where
591+ taggedObjectEnc' :: Options -> String -> f a -> Tagged isRecord Encoding
592+
593+instance OVERLAPPING_ TaggedObjectEnc' U1 False where
594+ taggedObjectEnc' _ _ _ = Tagged mempty
595+
596+instance (RecordToEncoding f) => TaggedObjectEnc' f True where
597+ taggedObjectEnc' opts _ = Tagged . (E.comma <>) . fst . recordToEncoding opts
598+
599+instance (GToEncoding f) => TaggedObjectEnc' f False where
600+ taggedObjectEnc' opts contentsFieldName =
601+ Tagged . (\z -> E.comma <> toEncoding contentsFieldName <> E.colon <> z) .
602+ gToEncoding opts
603+
604+--------------------------------------------------------------------------------
605+
606+-- | Get the name of the constructor of a sum datatype.
607+class GetConName f where
608+ getConName :: f a -> String
609+
610+instance (GetConName a, GetConName b) => GetConName (a :+: b) where
611+ getConName (L1 x) = getConName x
612+ getConName (R1 x) = getConName x
613+
614+instance (Constructor c) => GetConName (C1 c a) where
615+ getConName = conName
616+
617+--------------------------------------------------------------------------------
618+
619+class TwoElemArrayObj f where
620+ twoElemArrayObj :: Options -> f a -> V.Vector Value
621+
622+instance (TwoElemArrayObj a, TwoElemArrayObj b) => TwoElemArrayObj (a :+: b) where
623+ twoElemArrayObj opts (L1 x) = twoElemArrayObj opts x
624+ twoElemArrayObj opts (R1 x) = twoElemArrayObj opts x
625+
626+instance ( GToJSON a, ConsToJSON a
627+ , Constructor c ) => TwoElemArrayObj (C1 c a) where
628+ twoElemArrayObj opts x = V.create $ do
629+ mv <- VM.unsafeNew 2
630+ VM.unsafeWrite mv 0 $ String $ pack $ constructorTagModifier opts
631+ $ conName (undefined :: t c a p)
632+ VM.unsafeWrite mv 1 $ gToJSON opts x
633+ return mv
634+
635+--------------------------------------------------------------------------------
636+
637+class TwoElemArrayEnc f where
638+ twoElemArrayEnc :: Options -> f a -> Encoding
639+
640+instance (TwoElemArrayEnc a, TwoElemArrayEnc b) => TwoElemArrayEnc (a :+: b) where
641+ twoElemArrayEnc opts (L1 x) = twoElemArrayEnc opts x
642+ twoElemArrayEnc opts (R1 x) = twoElemArrayEnc opts x
643+
644+instance ( GToEncoding a, ConsToEncoding a
645+ , Constructor c ) => TwoElemArrayEnc (C1 c a) where
646+ twoElemArrayEnc opts x = E.tuple $
647+ toEncoding (constructorTagModifier opts (conName (undefined :: t c a p))) >*<
648+ gToEncoding opts x
649+
650+--------------------------------------------------------------------------------
651+
652+class ConsToJSON f where
653+ consToJSON :: Options -> f a -> Value
654+
655+class ConsToJSON' f isRecord where
656+ consToJSON' :: Options -> Bool -- ^ Are we a record with one field?
657+ -> f a -> Tagged isRecord Value
658+
659+instance ( IsRecord f isRecord
660+ , ConsToJSON' f isRecord ) => ConsToJSON f where
661+ consToJSON opts = (unTagged :: Tagged isRecord Value -> Value)
662+ . consToJSON' opts (isUnary (undefined :: f a))
663+
664+instance (RecordToPairs f) => ConsToJSON' f True where
665+ consToJSON' opts isUn f = let
666+ vals = toList $ recordToPairs opts f
667+ in case (unwrapUnaryRecords opts,isUn,vals) of
668+ (True,True,[(_,val)]) -> Tagged val
669+ _ -> Tagged $ object vals
670+
671+instance GToJSON f => ConsToJSON' f False where
672+ consToJSON' opts _ = Tagged . gToJSON opts
673+
674+--------------------------------------------------------------------------------
675+
676+class ConsToEncoding f where
677+ consToEncoding :: Options -> f a -> Encoding
678+
679+class ConsToEncoding' f isRecord where
680+ consToEncoding' :: Options -> Bool -- ^ Are we a record with one field?
681+ -> f a -> Tagged isRecord Encoding
682+
683+instance ( IsRecord f isRecord
684+ , ConsToEncoding' f isRecord ) => ConsToEncoding f where
685+ consToEncoding opts = (unTagged :: Tagged isRecord Encoding -> Encoding)
686+ . consToEncoding' opts (isUnary (undefined :: f a))
687+
688+instance (RecordToEncoding f) => ConsToEncoding' f True where
689+ consToEncoding' opts isUn x =
690+ let (enc, mbVal) = recordToEncoding opts x
691+ in case (unwrapUnaryRecords opts, isUn, mbVal) of
692+ (True, True, Just val) -> Tagged val
693+ _ -> Tagged $ E.wrapObject enc
694+
695+instance GToEncoding f => ConsToEncoding' f False where
696+ consToEncoding' opts _ = Tagged . gToEncoding opts
697+
698+--------------------------------------------------------------------------------
699+
700+class RecordToPairs f where
701+ recordToPairs :: Options -> f a -> DList Pair
702+
703+instance (RecordToPairs a, RecordToPairs b) => RecordToPairs (a :*: b) where
704+ recordToPairs opts (a :*: b) = recordToPairs opts a <>
705+ recordToPairs opts b
706+
707+instance (Selector s, GToJSON a) => RecordToPairs (S1 s a) where
708+ recordToPairs = fieldToPair
709+
710+instance OVERLAPPING_ (Selector s, ToJSON a) =>
711+ RecordToPairs (S1 s (K1 i (Maybe a))) where
712+ recordToPairs opts (M1 k1) | omitNothingFields opts
713+ , K1 Nothing <- k1 = DList.empty
714+ recordToPairs opts m1 = fieldToPair opts m1
715+
716+fieldToPair :: (Selector s, GToJSON a) => Options -> S1 s a p -> DList Pair
717+fieldToPair opts m1 = pure ( pack $ fieldLabelModifier opts $ selName m1
718+ , gToJSON opts (unM1 m1)
719+ )
720+
721+--------------------------------------------------------------------------------
722+
723+class RecordToEncoding f where
724+ -- 1st element: whole thing
725+ -- 2nd element: in case the record has only 1 field, just the value
726+ -- of the field (without the key); 'Nothing' otherwise
727+ recordToEncoding :: Options -> f a -> (Encoding, Maybe Encoding)
728+
729+instance (RecordToEncoding a, RecordToEncoding b) => RecordToEncoding (a :*: b) where
730+ recordToEncoding opts (a :*: b) | omitNothingFields opts =
731+ (mconcat $ intersperse E.comma $
732+ filter (not . E.nullEncoding)
733+ [fst (recordToEncoding opts a), fst (recordToEncoding opts b)]
734+ , Nothing)
735+ recordToEncoding opts (a :*: b) =
736+ (fst (recordToEncoding opts a) <> E.comma <>
737+ fst (recordToEncoding opts b),
738+ Nothing)
739+
740+instance (Selector s, GToEncoding a) => RecordToEncoding (S1 s a) where
741+ recordToEncoding = fieldToEncoding
742+
743+instance OVERLAPPING_ (Selector s, ToJSON a) =>
744+ RecordToEncoding (S1 s (K1 i (Maybe a))) where
745+ recordToEncoding opts (M1 k1) | omitNothingFields opts
746+ , K1 Nothing <- k1 = (mempty, Nothing)
747+ recordToEncoding opts m1 = fieldToEncoding opts m1
748+
749+fieldToEncoding :: (Selector s, GToEncoding a) => Options -> S1 s a p -> (Encoding, Maybe Encoding)
750+fieldToEncoding opts m1 =
751+ let keyBuilder = toEncoding (fieldLabelModifier opts $ selName m1)
752+ valueBuilder = gToEncoding opts (unM1 m1)
753+ in (keyBuilder <> E.colon <> valueBuilder, Just valueBuilder)
754+
755+--------------------------------------------------------------------------------
756+
757+class WriteProduct f where
758+ writeProduct :: Options
759+ -> VM.MVector s Value
760+ -> Int -- ^ index
761+ -> Int -- ^ length
762+ -> f a
763+ -> ST s ()
764+
765+instance ( WriteProduct a
766+ , WriteProduct b ) => WriteProduct (a :*: b) where
767+ writeProduct opts mv ix len (a :*: b) = do
768+ writeProduct opts mv ix lenL a
769+ writeProduct opts mv ixR lenR b
770+ where
771+ lenL = len `unsafeShiftR` 1
772+ lenR = len - lenL
773+ ixR = ix + lenL
774+
775+instance OVERLAPPABLE_ (GToJSON a) => WriteProduct a where
776+ writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
777+
778+--------------------------------------------------------------------------------
779+
780+class EncodeProduct f where
781+ encodeProduct :: Options -> f a -> Encoding
782+
783+instance ( EncodeProduct a
784+ , EncodeProduct b ) => EncodeProduct (a :*: b) where
785+ encodeProduct opts (a :*: b) | omitNothingFields opts =
786+ mconcat $ intersperse E.comma $
787+ filter (not . E.nullEncoding)
788+ [encodeProduct opts a, encodeProduct opts b]
789+ encodeProduct opts (a :*: b) = encodeProduct opts a <>
790+ E.comma <>
791+ encodeProduct opts b
792+
793+instance OVERLAPPABLE_ (GToEncoding a) => EncodeProduct a where
794+ encodeProduct opts = gToEncoding opts
795+
796+--------------------------------------------------------------------------------
797+
798+class ObjectWithSingleFieldObj f where
799+ objectWithSingleFieldObj :: Options -> f a -> Object
800+
801+instance ( ObjectWithSingleFieldObj a
802+ , ObjectWithSingleFieldObj b ) => ObjectWithSingleFieldObj (a :+: b) where
803+ objectWithSingleFieldObj opts (L1 x) = objectWithSingleFieldObj opts x
804+ objectWithSingleFieldObj opts (R1 x) = objectWithSingleFieldObj opts x
805+
806+instance ( GToJSON a, ConsToJSON a
807+ , Constructor c ) => ObjectWithSingleFieldObj (C1 c a) where
808+ objectWithSingleFieldObj opts = H.singleton typ . gToJSON opts
809+ where
810+ typ = pack $ constructorTagModifier opts $
811+ conName (undefined :: t c a p)
812+
813+--------------------------------------------------------------------------------
814+
815+class ObjectWithSingleFieldEnc f where
816+ objectWithSingleFieldEnc :: Options -> f a -> Encoding
817+
818+instance ( ObjectWithSingleFieldEnc a
819+ , ObjectWithSingleFieldEnc b ) => ObjectWithSingleFieldEnc (a :+: b) where
820+ objectWithSingleFieldEnc opts (L1 x) = objectWithSingleFieldEnc opts x
821+ objectWithSingleFieldEnc opts (R1 x) = objectWithSingleFieldEnc opts x
822+
823+instance ( GToEncoding a, ConsToEncoding a
824+ , Constructor c ) => ObjectWithSingleFieldEnc (C1 c a) where
825+ objectWithSingleFieldEnc opts v =
826+ E.openCurly <>
827+ toEncoding
828+ (constructorTagModifier opts
829+ (conName (undefined :: t c a p))) <>
830+ E.colon <>
831+ gToEncoding opts v <>
832+ E.closeCurly
833+
834+-------------------------------------------------------------------------------
835+-- Instances
836+-------------------------------------------------------------------------------
837+
838+
839+
840+-------------------------------------------------------------------------------
841+-- base
842+-------------------------------------------------------------------------------
843+
844+instance ToJSON1 Identity where
845+ liftToJSON t _ (Identity a) = t a
846+ {-# INLINE liftToJSON #-}
847+
848+ liftToEncoding t _ (Identity a) = t a
849+ {-# INLINE liftToEncoding #-}
850+
851+instance (ToJSON a) => ToJSON (Identity a) where
852+ toJSON = toJSON1
853+ {-# INLINE toJSON #-}
854+
855+ toEncoding = toEncoding1
856+ {-# INLINE toEncoding #-}
857+
858+
859+instance ToJSON2 Const where
860+ liftToJSON2 t _ _ _ (Const x) = t x
861+ {-# INLINE liftToJSON2 #-}
862+
863+ liftToEncoding2 t _ _ _ (Const x) = t x
864+ {-# INLINE liftToEncoding2 #-}
865+
866+instance ToJSON a => ToJSON1 (Const a) where
867+ liftToJSON _ _ (Const x) = toJSON x
868+ {-# INLINE liftToJSON #-}
869+
870+ liftToEncoding _ _ (Const x) = toEncoding x
871+ {-# INLINE liftToEncoding #-}
872+
873+instance ToJSON a => ToJSON (Const a b) where
874+ toJSON (Const x) = toJSON x
875+ {-# INLINE toJSON #-}
876+
877+ toEncoding (Const x) = toEncoding x
878+ {-# INLINE toEncoding #-}
879+
880+
881+instance ToJSON1 Maybe where
882+ liftToJSON t _ (Just a) = t a
883+ liftToJSON _ _ Nothing = Null
884+ {-# INLINE liftToJSON #-}
885+
886+ liftToEncoding t _ (Just a) = t a
887+ liftToEncoding _ _ Nothing = Encoding EB.null_
888+ {-# INLINE liftToEncoding #-}
889+
890+instance (ToJSON a) => ToJSON (Maybe a) where
891+ toJSON = toJSON1
892+ {-# INLINE toJSON #-}
893+
894+ toEncoding = toEncoding1
895+ {-# INLINE toEncoding #-}
896+
897+
898+instance ToJSON2 Either where
899+ liftToJSON2 toA _ _toB _ (Left a) = Object $ H.singleton left (toA a)
900+ liftToJSON2 _toA _ toB _ (Right b) = Object $ H.singleton right (toB b)
901+ {-# INLINE liftToJSON2 #-}
902+
903+ liftToEncoding2 toA _ _toB _ (Left a) =
904+ Encoding (B.shortByteString "{\"Left\":")
905+ <> toA a
906+ <> Encoding (B.char7 '}')
907+
908+ liftToEncoding2 _toA _ toB _ (Right b) =
909+ Encoding (B.shortByteString "{\"Right\":")
910+ <> toB b
911+ <> Encoding (B.char7 '}')
912+ {-# INLINE liftToEncoding2 #-}
913+
914+instance (ToJSON a) => ToJSON1 (Either a) where
915+ liftToJSON = liftToJSON2 toJSON toJSONList
916+ {-# INLINE liftToJSON #-}
917+
918+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
919+ {-# INLINE liftToEncoding #-}
920+
921+instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
922+ toJSON = toJSON2
923+ {-# INLINE toJSON #-}
924+
925+ toEncoding = toEncoding2
926+ {-# INLINE toEncoding #-}
927+
928+left, right :: Text
929+left = "Left"
930+right = "Right"
931+
932+
933+instance ToJSON Bool where
934+ toJSON = Bool
935+ {-# INLINE toJSON #-}
936+
937+ toEncoding = Encoding . EB.bool
938+ {-# INLINE toEncoding #-}
939+
940+
941+instance ToJSON Ordering where
942+ toJSON = toJSON . orderingToText
943+ toEncoding = toEncoding . orderingToText
944+
945+orderingToText :: Ordering -> T.Text
946+orderingToText o = case o of
947+ LT -> "LT"
948+ EQ -> "EQ"
949+ GT -> "GT"
950+
951+instance ToJSON () where
952+ toJSON _ = emptyArray
953+ {-# INLINE toJSON #-}
954+
955+ toEncoding _ = emptyArray_
956+ {-# INLINE toEncoding #-}
957+
958+
959+instance ToJSON Char where
960+ toJSON = String . T.singleton
961+ {-# INLINE toJSON #-}
962+
963+ toJSONList = String . T.pack
964+ {-# INLINE toJSONList #-}
965+
966+ toEncoding = Encoding . EB.string . (:[])
967+ {-# INLINE toEncoding #-}
968+
969+ toEncodingList = Encoding . EB.string
970+ {-# INLINE toEncodingList #-}
971+
972+
973+instance ToJSON Double where
974+ toJSON = realFloatToJSON
975+ {-# INLINE toJSON #-}
976+
977+ toEncoding = realFloatToEncoding
978+ {-# INLINE toEncoding #-}
979+
980+
981+instance ToJSON Number where
982+ toJSON (D d) = toJSON d
983+ toJSON (I i) = toJSON i
984+ {-# INLINE toJSON #-}
985+
986+ toEncoding (D d) = toEncoding d
987+ toEncoding (I i) = toEncoding i
988+ {-# INLINE toEncoding #-}
989+
990+
991+instance ToJSON Float where
992+ toJSON = realFloatToJSON
993+ {-# INLINE toJSON #-}
994+
995+ toEncoding = realFloatToEncoding
996+ {-# INLINE toEncoding #-}
997+
998+
999+instance ToJSON (Ratio Integer) where
1000+ toJSON r = object [ "numerator" .= numerator r
1001+ , "denominator" .= denominator r
1002+ ]
1003+ {-# INLINE toJSON #-}
1004+
1005+ toEncoding r = Encoding $
1006+ B.shortByteString "{\"numerator\":" <> builder (numerator r) <>
1007+ B.shortByteString ",\"denominator\":" <> builder (denominator r) <>
1008+ B.char7 '}'
1009+ {-# INLINE toEncoding #-}
1010+
1011+
1012+instance HasResolution a => ToJSON (Fixed a) where
1013+ toJSON = Number . realToFrac
1014+ {-# INLINE toJSON #-}
1015+
1016+ toEncoding = Encoding . EB.number . realToFrac
1017+ {-# INLINE toEncoding #-}
1018+
1019+
1020+instance ToJSON Int where
1021+ toJSON = Number . fromIntegral
1022+ {-# INLINE toJSON #-}
1023+
1024+ toEncoding = Encoding . B.intDec
1025+ {-# INLINE toEncoding #-}
1026+
1027+instance ToJSON Integer where
1028+ toJSON = Number . fromInteger
1029+ {-# INLINE toJSON #-}
1030+
1031+ toEncoding = Encoding . B.integerDec
1032+ {-# INLINE toEncoding #-}
1033+
1034+
1035+instance ToJSON Natural where
1036+ toJSON = toJSON . toInteger
1037+ {-# INLINE toJSON #-}
1038+
1039+ toEncoding = toEncoding . toInteger
1040+ {-# INLINE toEncoding #-}
1041+
1042+
1043+instance ToJSON Int8 where
1044+ toJSON = Number . fromIntegral
1045+ {-# INLINE toJSON #-}
1046+
1047+ toEncoding = Encoding . B.int8Dec
1048+ {-# INLINE toEncoding #-}
1049+
1050+
1051+instance ToJSON Int16 where
1052+ toJSON = Number . fromIntegral
1053+ {-# INLINE toJSON #-}
1054+
1055+ toEncoding = Encoding . B.int16Dec
1056+ {-# INLINE toEncoding #-}
1057+
1058+
1059+instance ToJSON Int32 where
1060+ toJSON = Number . fromIntegral
1061+ {-# INLINE toJSON #-}
1062+
1063+ toEncoding = Encoding . B.int32Dec
1064+ {-# INLINE toEncoding #-}
1065+
1066+
1067+instance ToJSON Int64 where
1068+ toJSON = Number . fromIntegral
1069+ {-# INLINE toJSON #-}
1070+
1071+ toEncoding = Encoding . B.int64Dec
1072+ {-# INLINE toEncoding #-}
1073+
1074+
1075+instance ToJSON Word where
1076+ toJSON = Number . fromIntegral
1077+ {-# INLINE toJSON #-}
1078+
1079+ toEncoding = Encoding . B.wordDec
1080+ {-# INLINE toEncoding #-}
1081+
1082+
1083+instance ToJSON Word8 where
1084+ toJSON = Number . fromIntegral
1085+ {-# INLINE toJSON #-}
1086+
1087+ toEncoding = Encoding . B.word8Dec
1088+ {-# INLINE toEncoding #-}
1089+
1090+
1091+instance ToJSON Word16 where
1092+ toJSON = Number . fromIntegral
1093+ {-# INLINE toJSON #-}
1094+
1095+ toEncoding = Encoding . B.word16Dec
1096+ {-# INLINE toEncoding #-}
1097+
1098+
1099+instance ToJSON Word32 where
1100+ toJSON = Number . fromIntegral
1101+ {-# INLINE toJSON #-}
1102+
1103+ toEncoding = Encoding . B.word32Dec
1104+ {-# INLINE toEncoding #-}
1105+
1106+instance ToJSON Word64 where
1107+ toJSON = Number . fromIntegral
1108+ {-# INLINE toJSON #-}
1109+
1110+ toEncoding = Encoding . B.word64Dec
1111+ {-# INLINE toEncoding #-}
1112+
1113+instance ToJSON Text where
1114+ toJSON = String
1115+ {-# INLINE toJSON #-}
1116+
1117+ toEncoding = Encoding . EB.text
1118+ {-# INLINE toEncoding #-}
1119+
1120+instance ToJSON LT.Text where
1121+ toJSON = String . LT.toStrict
1122+ {-# INLINE toJSON #-}
1123+
1124+ toEncoding t = Encoding $
1125+ B.char7 '"' <>
1126+ LT.foldrChunks (\x xs -> EB.unquoted x <> xs) (B.char7 '"') t
1127+ {-# INLINE toEncoding #-}
1128+
1129+instance ToJSON Version where
1130+ toJSON = toJSON . showVersion
1131+ {-# INLINE toJSON #-}
1132+
1133+ toEncoding = toEncoding . showVersion
1134+ {-# INLINE toEncoding #-}
1135+
1136+
1137+-------------------------------------------------------------------------------
1138+-- semigroups NonEmpty
1139+-------------------------------------------------------------------------------
1140+
1141+instance ToJSON1 NonEmpty where
1142+ liftToJSON t _ = listValue t . NE.toList
1143+ {-# INLINE liftToJSON #-}
1144+
1145+ liftToEncoding t _ = listEncoding t . NE.toList
1146+ {-# INLINE liftToEncoding #-}
1147+
1148+instance (ToJSON a) => ToJSON (NonEmpty a) where
1149+ toJSON = toJSON1
1150+ {-# INLINE toJSON #-}
1151+
1152+ toEncoding = toEncoding1
1153+ {-# INLINE toEncoding #-}
1154+
1155+-------------------------------------------------------------------------------
1156+-- scientific
1157+-------------------------------------------------------------------------------
1158+
1159+instance ToJSON Scientific where
1160+ toJSON = Number
1161+ {-# INLINE toJSON #-}
1162+
1163+ toEncoding = Encoding . EB.number
1164+ {-# INLINE toEncoding #-}
1165+
1166+-------------------------------------------------------------------------------
1167+-- containers
1168+-------------------------------------------------------------------------------
1169+
1170+instance ToJSON1 Seq.Seq where
1171+ liftToJSON t _ = listValue t . toList
1172+ {-# INLINE liftToJSON #-}
1173+
1174+ liftToEncoding t _ = listEncoding t . toList
1175+ {-# INLINE liftToEncoding #-}
1176+
1177+instance (ToJSON a) => ToJSON (Seq.Seq a) where
1178+ toJSON = toJSON1
1179+ {-# INLINE toJSON #-}
1180+
1181+ toEncoding = toEncoding1
1182+ {-# INLINE toEncoding #-}
1183+
1184+
1185+instance ToJSON1 Set.Set where
1186+ liftToJSON t _ = listValue t . Set.toList
1187+ {-# INLINE liftToJSON #-}
1188+
1189+ liftToEncoding t _ = listEncoding t . Set.toList
1190+ {-# INLINE liftToEncoding #-}
1191+
1192+instance (ToJSON a) => ToJSON (Set.Set a) where
1193+ toJSON = toJSON1
1194+ {-# INLINE toJSON #-}
1195+
1196+ toEncoding = toEncoding1
1197+ {-# INLINE toEncoding #-}
1198+
1199+
1200+instance ToJSON IntSet.IntSet where
1201+ toJSON = toJSON . IntSet.toList
1202+ {-# INLINE toJSON #-}
1203+
1204+ toEncoding = toEncoding . IntSet.toList
1205+ {-# INLINE toEncoding #-}
1206+
1207+
1208+instance ToJSON1 IntMap.IntMap where
1209+ liftToJSON t tol = liftToJSON to' tol' . IntMap.toList
1210+ where
1211+ to' = liftToJSON2 toJSON toJSONList t tol
1212+ tol' = liftToJSONList2 toJSON toJSONList t tol
1213+ {-# INLINE liftToJSON #-}
1214+
1215+ liftToEncoding t tol = liftToEncoding to' tol' . IntMap.toList
1216+ where
1217+ to' = liftToEncoding2 toEncoding toEncodingList t tol
1218+ tol' = liftToEncodingList2 toEncoding toEncodingList t tol
1219+ {-# INLINE liftToEncoding #-}
1220+
1221+instance ToJSON a => ToJSON (IntMap.IntMap a) where
1222+ toJSON = toJSON1
1223+ {-# INLINE toJSON #-}
1224+
1225+ toEncoding = toEncoding1
1226+ {-# INLINE toEncoding #-}
1227+
1228+
1229+instance ToJSONKey k => ToJSON1 (M.Map k) where
1230+ liftToJSON g _ = case toJSONKey of
1231+ ToJSONKeyText (f,_) -> Object . mapHashKeyVal f g
1232+ ToJSONKeyValue (f,_) -> Array . V.fromList . map (toJSONPair f g) . M.toList
1233+ {-# INLINE liftToJSON #-}
1234+
1235+ -- liftToEncoding :: forall a. (a -> Encoding) -> ([a] -> Encoding) -> M.Map k a -> Encoding
1236+ liftToEncoding g _ = case toJSONKey of
1237+ ToJSONKeyText (_,f) -> dict f g M.foldrWithKey
1238+ ToJSONKeyValue (_,f) -> listEncoding (pairEncoding f) . M.toList
1239+ where
1240+ -- pairEncoding :: (k -> Encoding) -> (k, a) -> Encoding
1241+ pairEncoding f (a, b) = tuple $ f a >*< g b
1242+ {-# INLINE liftToEncoding #-}
1243+
1244+
1245+instance (ToJSON v, ToJSONKey k) => ToJSON (M.Map k v) where
1246+ toJSON = toJSON1
1247+ {-# INLINE toJSON #-}
1248+
1249+ toEncoding = toEncoding1
1250+ {-# INLINE toEncoding #-}
1251+
1252+
1253+instance ToJSON1 Tree.Tree where
1254+ liftToJSON t tol = go
1255+ where
1256+ go (Tree.Node root branches) =
1257+ liftToJSON2 t tol to' tol' (root, branches)
1258+
1259+ to' = liftToJSON go (listValue go)
1260+ tol' = liftToJSONList go (listValue go)
1261+ {-# INLINE liftToJSON #-}
1262+
1263+ liftToEncoding t tol = go
1264+ where
1265+ go (Tree.Node root branches) =
1266+ liftToEncoding2 t tol to' tol' (root, branches)
1267+
1268+ to' = liftToEncoding go (listEncoding go)
1269+ tol' = liftToEncodingList go (listEncoding go)
1270+ {-# INLINE liftToEncoding #-}
1271+
1272+instance (ToJSON v) => ToJSON (Tree.Tree v) where
1273+ toJSON = toJSON1
1274+ {-# INLINE toJSON #-}
1275+
1276+ toEncoding = toEncoding1
1277+ {-# INLINE toEncoding #-}
1278+
1279+
1280+-------------------------------------------------------------------------------
1281+-- vector
1282+-------------------------------------------------------------------------------
1283+
1284+instance ToJSON1 Vector where
1285+ liftToJSON t _ = Array . V.map t
1286+ {-# INLINE liftToJSON #-}
1287+
1288+ liftToEncoding t _ xs
1289+ | V.null xs = emptyArray_
1290+ | otherwise = Encoding $
1291+ B.char7 '[' <> fromEncoding (t (V.unsafeHead xs)) <>
1292+ V.foldr go (B.char7 ']') (V.unsafeTail xs)
1293+ where
1294+ go v b = B.char7 ',' <> fromEncoding (t v) <> b
1295+ {-# INLINE liftToEncoding #-}
1296+
1297+instance (ToJSON a) => ToJSON (Vector a) where
1298+ toJSON = Array . V.map toJSON
1299+ {-# INLINE toJSON #-}
1300+
1301+ toEncoding = encodeVector
1302+ {-# INLINE toEncoding #-}
1303+
1304+encodeVector :: (ToJSON a, VG.Vector v a) => v a -> Encoding
1305+encodeVector xs
1306+ | VG.null xs = emptyArray_
1307+ | otherwise = Encoding $
1308+ B.char7 '[' <> builder (VG.unsafeHead xs) <>
1309+ VG.foldr go (B.char7 ']') (VG.unsafeTail xs)
1310+ where go v b = B.char7 ',' <> builder v <> b
1311+{-# INLINE encodeVector #-}
1312+
1313+vectorToJSON :: (VG.Vector v a, ToJSON a) => v a -> Value
1314+vectorToJSON = Array . V.map toJSON . V.convert
1315+{-# INLINE vectorToJSON #-}
1316+
1317+instance (Storable a, ToJSON a) => ToJSON (VS.Vector a) where
1318+ toJSON = vectorToJSON
1319+ {-# INLINE toJSON #-}
1320+
1321+ toEncoding = encodeVector
1322+ {-# INLINE toEncoding #-}
1323+
1324+
1325+instance (VP.Prim a, ToJSON a) => ToJSON (VP.Vector a) where
1326+ toJSON = vectorToJSON
1327+ {-# INLINE toJSON #-}
1328+
1329+ toEncoding = encodeVector
1330+ {-# INLINE toEncoding #-}
1331+
1332+
1333+instance (VG.Vector VU.Vector a, ToJSON a) => ToJSON (VU.Vector a) where
1334+ toJSON = vectorToJSON
1335+ {-# INLINE toJSON #-}
1336+
1337+ toEncoding = encodeVector
1338+ {-# INLINE toEncoding #-}
1339+
1340+-------------------------------------------------------------------------------
1341+-- unordered-containers
1342+-------------------------------------------------------------------------------
1343+
1344+instance ToJSON1 HashSet.HashSet where
1345+ liftToJSON t _ = listValue t . HashSet.toList
1346+ {-# INLINE liftToJSON #-}
1347+
1348+ liftToEncoding t _ = listEncoding t . HashSet.toList
1349+ {-# INLINE liftToEncoding #-}
1350+
1351+instance (ToJSON a) => ToJSON (HashSet.HashSet a) where
1352+ toJSON = toJSON1
1353+ {-# INLINE toJSON #-}
1354+
1355+ toEncoding = toEncoding1
1356+ {-# INLINE toEncoding #-}
1357+
1358+
1359+instance ToJSONKey k => ToJSON1 (H.HashMap k) where
1360+ liftToJSON g _ = case toJSONKey of
1361+ ToJSONKeyText (f,_) -> Object . mapKeyVal f g
1362+ ToJSONKeyValue (f,_) -> Array . V.fromList . map (toJSONPair f g) . H.toList
1363+ {-# INLINE liftToJSON #-}
1364+
1365+ -- liftToEncoding :: forall a. (a -> Encoding) -> ([a] -> Encoding) -> H.HashMap k a -> Encoding
1366+ liftToEncoding g _ = case toJSONKey of
1367+ ToJSONKeyText (_,f) -> dict f g H.foldrWithKey
1368+ ToJSONKeyValue (_,f) -> listEncoding (pairEncoding f) . H.toList
1369+ where
1370+ -- pairEncoding :: (k -> Encoding) -> (k, a) -> Encoding
1371+ pairEncoding f (a, b) = tuple $ f a >*< g b
1372+ {-# INLINE liftToEncoding #-}
1373+
1374+instance (ToJSON v, ToJSONKey k) => ToJSON (H.HashMap k v) where
1375+ toJSON = toJSON1
1376+ {-# INLINE toJSON #-}
1377+
1378+ toEncoding = toEncoding1
1379+ {-# INLINE toEncoding #-}
1380+
1381+-------------------------------------------------------------------------------
1382+-- aeson
1383+-------------------------------------------------------------------------------
1384+
1385+instance ToJSON Value where
1386+ toJSON a = a
1387+ {-# INLINE toJSON #-}
1388+
1389+ toEncoding = Encoding . EB.encodeToBuilder
1390+ {-# INLINE toEncoding #-}
1391+
1392+instance ToJSON DotNetTime where
1393+ toJSON = toJSON . dotNetTime
1394+
1395+ toEncoding = toEncoding . dotNetTime
1396+
1397+dotNetTime :: DotNetTime -> String
1398+dotNetTime (DotNetTime t) = secs ++ formatMillis t ++ ")/"
1399+ where secs = formatTime defaultTimeLocale "/Date(%s" t
1400+
1401+-------------------------------------------------------------------------------
1402+-- time
1403+-------------------------------------------------------------------------------
1404+
1405+instance ToJSON Day where
1406+ toJSON = stringEncoding
1407+ toEncoding z = Encoding (EB.quote $ EB.day z)
1408+
1409+
1410+instance ToJSON TimeOfDay where
1411+ toJSON = stringEncoding
1412+ toEncoding z = Encoding (EB.quote $ EB.timeOfDay z)
1413+
1414+
1415+instance ToJSON LocalTime where
1416+ toJSON = stringEncoding
1417+ toEncoding z = Encoding (EB.quote $ EB.localTime z)
1418+
1419+instance ToJSON ZonedTime where
1420+ toJSON = stringEncoding
1421+
1422+ toEncoding z = Encoding (EB.quote $ EB.zonedTime z)
1423+
1424+formatMillis :: (FormatTime t) => t -> String
1425+formatMillis = take 3 . formatTime defaultTimeLocale "%q"
1426+
1427+instance ToJSON UTCTime where
1428+ toJSON = stringEncoding
1429+
1430+ toEncoding t = Encoding (EB.quote $ EB.utcTime t)
1431+
1432+-- | Encode something t a JSON string.
1433+--
1434+-- TODO: remove me, this is a hack
1435+stringEncoding :: (ToJSON a) => a -> Value
1436+stringEncoding = String
1437+ . T.dropAround (== '"')
1438+ . T.decodeLatin1
1439+ . L.toStrict
1440+ . B.toLazyByteString
1441+ . fromEncoding
1442+ . toEncoding
1443+{-# INLINE stringEncoding #-}
1444+
1445+instance ToJSON NominalDiffTime where
1446+ toJSON = Number . realToFrac
1447+ {-# INLINE toJSON #-}
1448+
1449+ toEncoding = Encoding . EB.number . realToFrac
1450+ {-# INLINE toEncoding #-}
1451+
1452+-------------------------------------------------------------------------------
1453+-- base Monoid/Semigroup
1454+-------------------------------------------------------------------------------
1455+
1456+instance ToJSON1 Dual where
1457+ liftToJSON t _ = t . getDual
1458+ {-# INLINE liftToJSON #-}
1459+
1460+ liftToEncoding t _ = t . getDual
1461+ {-# INLINE liftToEncoding #-}
1462+
1463+instance ToJSON a => ToJSON (Dual a) where
1464+ toJSON = toJSON1
1465+ {-# INLINE toJSON #-}
1466+
1467+ toEncoding = toEncoding1
1468+ {-# INLINE toEncoding #-}
1469+
1470+
1471+instance ToJSON1 First where
1472+ liftToJSON t to' = liftToJSON t to' . getFirst
1473+ {-# INLINE liftToJSON #-}
1474+
1475+ liftToEncoding t to' = liftToEncoding t to' . getFirst
1476+ {-# INLINE liftToEncoding #-}
1477+
1478+instance ToJSON a => ToJSON (First a) where
1479+ toJSON = toJSON1
1480+ {-# INLINE toJSON #-}
1481+
1482+ toEncoding = toEncoding1
1483+ {-# INLINE toEncoding #-}
1484+
1485+
1486+instance ToJSON1 Last where
1487+ liftToJSON t to' = liftToJSON t to' . getLast
1488+ {-# INLINE liftToJSON #-}
1489+
1490+ liftToEncoding t to' = liftToEncoding t to' . getLast
1491+ {-# INLINE liftToEncoding #-}
1492+
1493+instance ToJSON a => ToJSON (Last a) where
1494+ toJSON = toJSON1
1495+ {-# INLINE toJSON #-}
1496+
1497+ toEncoding = toEncoding1
1498+ {-# INLINE toEncoding #-}
1499+
1500+-------------------------------------------------------------------------------
1501+-- tagged
1502+-------------------------------------------------------------------------------
1503+
1504+instance ToJSON (Proxy a) where
1505+ toJSON _ = Null
1506+ {-# INLINE toJSON #-}
1507+
1508+ toEncoding _ = Encoding EB.null_
1509+ {-# INLINE toEncoding #-}
1510+
1511+
1512+instance ToJSON1 (Tagged a) where
1513+ liftToJSON t _ (Tagged x) = t x
1514+ {-# INLINE liftToJSON #-}
1515+
1516+ liftToEncoding t _ (Tagged x) = t x
1517+ {-# INLINE liftToEncoding #-}
1518+
1519+instance ToJSON b => ToJSON (Tagged a b) where
1520+ toJSON = toJSON1
1521+ {-# INLINE toJSON #-}
1522+
1523+ toEncoding = toEncoding1
1524+ {-# INLINE toEncoding #-}
1525+
1526+
1527+instance ToJSONKey b => ToJSONKey (Tagged a b) where
1528+ toJSONKey = contramapToJSONKeyFunction unTagged toJSONKey
1529+ toJSONKeyList = contramapToJSONKeyFunction (fmap unTagged) toJSONKeyList
1530+
1531+-------------------------------------------------------------------------------
1532+-- Instances for converting t map keys
1533+-------------------------------------------------------------------------------
1534+
1535+instance ToJSONKey Text where
1536+ toJSONKey = ToJSONKeyText (id,toEncoding)
1537+
1538+
1539+instance ToJSONKey Bool where
1540+ toJSONKey = ToJSONKeyText
1541+ ( (\x -> if x then "true" else "false")
1542+ , (\x -> Encoding $ if x then "\"true\"" else "\"false\"")
1543+ )
1544+
1545+instance ToJSONKey Int where
1546+ toJSONKey = ToJSONKeyText
1547+ ( LT.toStrict . LTB.toLazyText . LTBI.decimal
1548+ , \x -> Encoding $ B.char7 '"' <> fromEncoding (toEncoding x) <> B.char7 '"'
1549+ )
1550+
1551+instance (ToJSON a, ToJSON b) => ToJSONKey (a,b)
1552+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSONKey (a,b,c)
1553+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSONKey (a,b,c,d)
1554+
1555+instance ToJSONKey Char where
1556+ toJSONKey = ToJSONKeyText (T.singleton, toEncoding)
1557+ toJSONKeyList = ToJSONKeyText (T.pack, toEncoding . T.pack)
1558+
1559+instance (ToJSONKey a, ToJSON a) => ToJSONKey [a] where
1560+ toJSONKey = toJSONKeyList
1561+
1562+instance (ToJSONKey a, ToJSON a) => ToJSONKey (Identity a) where
1563+ toJSONKey = contramapToJSONKeyFunction runIdentity toJSONKey
1564+
1565+-------------------------------------------------------------------------------
1566+-- Tuple instances, see tuple-instances-to.hs
1567+-------------------------------------------------------------------------------
1568+
1569+instance ToJSON2 ((,) ) where
1570+ liftToJSON2 toA _ toB _ (a, b) = Array $ V.create $ do
1571+ mv <- VM.unsafeNew 2
1572+ VM.unsafeWrite mv 0 (toA a)
1573+ VM.unsafeWrite mv 1 (toB b)
1574+ return mv
1575+ {-# INLINE liftToJSON2 #-}
1576+
1577+ liftToEncoding2 toA _ toB _ (a, b) = tuple $
1578+ toA a >*<
1579+ toB b
1580+ {-# INLINE liftToEncoding2 #-}
1581+
1582+instance (ToJSON a) => ToJSON1 ((,) a) where
1583+ liftToJSON = liftToJSON2 toJSON toJSONList
1584+ {-# INLINE liftToJSON #-}
1585+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1586+ {-# INLINE liftToEncoding #-}
1587+
1588+instance (ToJSON a, ToJSON b) => ToJSON (a, b) where
1589+ toJSON = toJSON2
1590+ {-# INLINE toJSON #-}
1591+ toEncoding = toEncoding2
1592+ {-# INLINE toEncoding #-}
1593+
1594+instance (ToJSON a) => ToJSON2 ((,,) a) where
1595+ liftToJSON2 toB _ toC _ (a, b, c) = Array $ V.create $ do
1596+ mv <- VM.unsafeNew 3
1597+ VM.unsafeWrite mv 0 (toJSON a)
1598+ VM.unsafeWrite mv 1 (toB b)
1599+ VM.unsafeWrite mv 2 (toC c)
1600+ return mv
1601+ {-# INLINE liftToJSON2 #-}
1602+
1603+ liftToEncoding2 toB _ toC _ (a, b, c) = tuple $
1604+ toEncoding a >*<
1605+ toB b >*<
1606+ toC c
1607+ {-# INLINE liftToEncoding2 #-}
1608+
1609+instance (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) where
1610+ liftToJSON = liftToJSON2 toJSON toJSONList
1611+ {-# INLINE liftToJSON #-}
1612+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1613+ {-# INLINE liftToEncoding #-}
1614+
1615+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) where
1616+ toJSON = toJSON2
1617+ {-# INLINE toJSON #-}
1618+ toEncoding = toEncoding2
1619+ {-# INLINE toEncoding #-}
1620+
1621+instance (ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) where
1622+ liftToJSON2 toC _ toD _ (a, b, c, d) = Array $ V.create $ do
1623+ mv <- VM.unsafeNew 4
1624+ VM.unsafeWrite mv 0 (toJSON a)
1625+ VM.unsafeWrite mv 1 (toJSON b)
1626+ VM.unsafeWrite mv 2 (toC c)
1627+ VM.unsafeWrite mv 3 (toD d)
1628+ return mv
1629+ {-# INLINE liftToJSON2 #-}
1630+
1631+ liftToEncoding2 toC _ toD _ (a, b, c, d) = tuple $
1632+ toEncoding a >*<
1633+ toEncoding b >*<
1634+ toC c >*<
1635+ toD d
1636+ {-# INLINE liftToEncoding2 #-}
1637+
1638+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) where
1639+ liftToJSON = liftToJSON2 toJSON toJSONList
1640+ {-# INLINE liftToJSON #-}
1641+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1642+ {-# INLINE liftToEncoding #-}
1643+
1644+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) where
1645+ toJSON = toJSON2
1646+ {-# INLINE toJSON #-}
1647+ toEncoding = toEncoding2
1648+ {-# INLINE toEncoding #-}
1649+
1650+instance (ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) where
1651+ liftToJSON2 toD _ toE _ (a, b, c, d, e) = Array $ V.create $ do
1652+ mv <- VM.unsafeNew 5
1653+ VM.unsafeWrite mv 0 (toJSON a)
1654+ VM.unsafeWrite mv 1 (toJSON b)
1655+ VM.unsafeWrite mv 2 (toJSON c)
1656+ VM.unsafeWrite mv 3 (toD d)
1657+ VM.unsafeWrite mv 4 (toE e)
1658+ return mv
1659+ {-# INLINE liftToJSON2 #-}
1660+
1661+ liftToEncoding2 toD _ toE _ (a, b, c, d, e) = tuple $
1662+ toEncoding a >*<
1663+ toEncoding b >*<
1664+ toEncoding c >*<
1665+ toD d >*<
1666+ toE e
1667+ {-# INLINE liftToEncoding2 #-}
1668+
1669+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) where
1670+ liftToJSON = liftToJSON2 toJSON toJSONList
1671+ {-# INLINE liftToJSON #-}
1672+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1673+ {-# INLINE liftToEncoding #-}
1674+
1675+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON (a, b, c, d, e) where
1676+ toJSON = toJSON2
1677+ {-# INLINE toJSON #-}
1678+ toEncoding = toEncoding2
1679+ {-# INLINE toEncoding #-}
1680+
1681+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) where
1682+ liftToJSON2 toE _ toF _ (a, b, c, d, e, f) = Array $ V.create $ do
1683+ mv <- VM.unsafeNew 6
1684+ VM.unsafeWrite mv 0 (toJSON a)
1685+ VM.unsafeWrite mv 1 (toJSON b)
1686+ VM.unsafeWrite mv 2 (toJSON c)
1687+ VM.unsafeWrite mv 3 (toJSON d)
1688+ VM.unsafeWrite mv 4 (toE e)
1689+ VM.unsafeWrite mv 5 (toF f)
1690+ return mv
1691+ {-# INLINE liftToJSON2 #-}
1692+
1693+ liftToEncoding2 toE _ toF _ (a, b, c, d, e, f) = tuple $
1694+ toEncoding a >*<
1695+ toEncoding b >*<
1696+ toEncoding c >*<
1697+ toEncoding d >*<
1698+ toE e >*<
1699+ toF f
1700+ {-# INLINE liftToEncoding2 #-}
1701+
1702+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) where
1703+ liftToJSON = liftToJSON2 toJSON toJSONList
1704+ {-# INLINE liftToJSON #-}
1705+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1706+ {-# INLINE liftToEncoding #-}
1707+
1708+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON (a, b, c, d, e, f) where
1709+ toJSON = toJSON2
1710+ {-# INLINE toJSON #-}
1711+ toEncoding = toEncoding2
1712+ {-# INLINE toEncoding #-}
1713+
1714+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,) a b c d e) where
1715+ liftToJSON2 toF _ toG _ (a, b, c, d, e, f, g) = Array $ V.create $ do
1716+ mv <- VM.unsafeNew 7
1717+ VM.unsafeWrite mv 0 (toJSON a)
1718+ VM.unsafeWrite mv 1 (toJSON b)
1719+ VM.unsafeWrite mv 2 (toJSON c)
1720+ VM.unsafeWrite mv 3 (toJSON d)
1721+ VM.unsafeWrite mv 4 (toJSON e)
1722+ VM.unsafeWrite mv 5 (toF f)
1723+ VM.unsafeWrite mv 6 (toG g)
1724+ return mv
1725+ {-# INLINE liftToJSON2 #-}
1726+
1727+ liftToEncoding2 toF _ toG _ (a, b, c, d, e, f, g) = tuple $
1728+ toEncoding a >*<
1729+ toEncoding b >*<
1730+ toEncoding c >*<
1731+ toEncoding d >*<
1732+ toEncoding e >*<
1733+ toF f >*<
1734+ toG g
1735+ {-# INLINE liftToEncoding2 #-}
1736+
1737+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) where
1738+ liftToJSON = liftToJSON2 toJSON toJSONList
1739+ {-# INLINE liftToJSON #-}
1740+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1741+ {-# INLINE liftToEncoding #-}
1742+
1743+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON (a, b, c, d, e, f, g) where
1744+ toJSON = toJSON2
1745+ {-# INLINE toJSON #-}
1746+ toEncoding = toEncoding2
1747+ {-# INLINE toEncoding #-}
1748+
1749+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2 ((,,,,,,,) a b c d e f) where
1750+ liftToJSON2 toG _ toH _ (a, b, c, d, e, f, g, h) = Array $ V.create $ do
1751+ mv <- VM.unsafeNew 8
1752+ VM.unsafeWrite mv 0 (toJSON a)
1753+ VM.unsafeWrite mv 1 (toJSON b)
1754+ VM.unsafeWrite mv 2 (toJSON c)
1755+ VM.unsafeWrite mv 3 (toJSON d)
1756+ VM.unsafeWrite mv 4 (toJSON e)
1757+ VM.unsafeWrite mv 5 (toJSON f)
1758+ VM.unsafeWrite mv 6 (toG g)
1759+ VM.unsafeWrite mv 7 (toH h)
1760+ return mv
1761+ {-# INLINE liftToJSON2 #-}
1762+
1763+ liftToEncoding2 toG _ toH _ (a, b, c, d, e, f, g, h) = tuple $
1764+ toEncoding a >*<
1765+ toEncoding b >*<
1766+ toEncoding c >*<
1767+ toEncoding d >*<
1768+ toEncoding e >*<
1769+ toEncoding f >*<
1770+ toG g >*<
1771+ toH h
1772+ {-# INLINE liftToEncoding2 #-}
1773+
1774+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) where
1775+ liftToJSON = liftToJSON2 toJSON toJSONList
1776+ {-# INLINE liftToJSON #-}
1777+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1778+ {-# INLINE liftToEncoding #-}
1779+
1780+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON (a, b, c, d, e, f, g, h) where
1781+ toJSON = toJSON2
1782+ {-# INLINE toJSON #-}
1783+ toEncoding = toEncoding2
1784+ {-# INLINE toEncoding #-}
1785+
1786+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON2 ((,,,,,,,,) a b c d e f g) where
1787+ liftToJSON2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = Array $ V.create $ do
1788+ mv <- VM.unsafeNew 9
1789+ VM.unsafeWrite mv 0 (toJSON a)
1790+ VM.unsafeWrite mv 1 (toJSON b)
1791+ VM.unsafeWrite mv 2 (toJSON c)
1792+ VM.unsafeWrite mv 3 (toJSON d)
1793+ VM.unsafeWrite mv 4 (toJSON e)
1794+ VM.unsafeWrite mv 5 (toJSON f)
1795+ VM.unsafeWrite mv 6 (toJSON g)
1796+ VM.unsafeWrite mv 7 (toH h)
1797+ VM.unsafeWrite mv 8 (toI i)
1798+ return mv
1799+ {-# INLINE liftToJSON2 #-}
1800+
1801+ liftToEncoding2 toH _ toI _ (a, b, c, d, e, f, g, h, i) = tuple $
1802+ toEncoding a >*<
1803+ toEncoding b >*<
1804+ toEncoding c >*<
1805+ toEncoding d >*<
1806+ toEncoding e >*<
1807+ toEncoding f >*<
1808+ toEncoding g >*<
1809+ toH h >*<
1810+ toI i
1811+ {-# INLINE liftToEncoding2 #-}
1812+
1813+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) where
1814+ liftToJSON = liftToJSON2 toJSON toJSONList
1815+ {-# INLINE liftToJSON #-}
1816+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1817+ {-# INLINE liftToEncoding #-}
1818+
1819+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON (a, b, c, d, e, f, g, h, i) where
1820+ toJSON = toJSON2
1821+ {-# INLINE toJSON #-}
1822+ toEncoding = toEncoding2
1823+ {-# INLINE toEncoding #-}
1824+
1825+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON2 ((,,,,,,,,,) a b c d e f g h) where
1826+ liftToJSON2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = Array $ V.create $ do
1827+ mv <- VM.unsafeNew 10
1828+ VM.unsafeWrite mv 0 (toJSON a)
1829+ VM.unsafeWrite mv 1 (toJSON b)
1830+ VM.unsafeWrite mv 2 (toJSON c)
1831+ VM.unsafeWrite mv 3 (toJSON d)
1832+ VM.unsafeWrite mv 4 (toJSON e)
1833+ VM.unsafeWrite mv 5 (toJSON f)
1834+ VM.unsafeWrite mv 6 (toJSON g)
1835+ VM.unsafeWrite mv 7 (toJSON h)
1836+ VM.unsafeWrite mv 8 (toI i)
1837+ VM.unsafeWrite mv 9 (toJ j)
1838+ return mv
1839+ {-# INLINE liftToJSON2 #-}
1840+
1841+ liftToEncoding2 toI _ toJ _ (a, b, c, d, e, f, g, h, i, j) = tuple $
1842+ toEncoding a >*<
1843+ toEncoding b >*<
1844+ toEncoding c >*<
1845+ toEncoding d >*<
1846+ toEncoding e >*<
1847+ toEncoding f >*<
1848+ toEncoding g >*<
1849+ toEncoding h >*<
1850+ toI i >*<
1851+ toJ j
1852+ {-# INLINE liftToEncoding2 #-}
1853+
1854+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) where
1855+ liftToJSON = liftToJSON2 toJSON toJSONList
1856+ {-# INLINE liftToJSON #-}
1857+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1858+ {-# INLINE liftToEncoding #-}
1859+
1860+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON (a, b, c, d, e, f, g, h, i, j) where
1861+ toJSON = toJSON2
1862+ {-# INLINE toJSON #-}
1863+ toEncoding = toEncoding2
1864+ {-# INLINE toEncoding #-}
1865+
1866+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON2 ((,,,,,,,,,,) a b c d e f g h i) where
1867+ liftToJSON2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = Array $ V.create $ do
1868+ mv <- VM.unsafeNew 11
1869+ VM.unsafeWrite mv 0 (toJSON a)
1870+ VM.unsafeWrite mv 1 (toJSON b)
1871+ VM.unsafeWrite mv 2 (toJSON c)
1872+ VM.unsafeWrite mv 3 (toJSON d)
1873+ VM.unsafeWrite mv 4 (toJSON e)
1874+ VM.unsafeWrite mv 5 (toJSON f)
1875+ VM.unsafeWrite mv 6 (toJSON g)
1876+ VM.unsafeWrite mv 7 (toJSON h)
1877+ VM.unsafeWrite mv 8 (toJSON i)
1878+ VM.unsafeWrite mv 9 (toJ j)
1879+ VM.unsafeWrite mv 10 (toK k)
1880+ return mv
1881+ {-# INLINE liftToJSON2 #-}
1882+
1883+ liftToEncoding2 toJ _ toK _ (a, b, c, d, e, f, g, h, i, j, k) = tuple $
1884+ toEncoding a >*<
1885+ toEncoding b >*<
1886+ toEncoding c >*<
1887+ toEncoding d >*<
1888+ toEncoding e >*<
1889+ toEncoding f >*<
1890+ toEncoding g >*<
1891+ toEncoding h >*<
1892+ toEncoding i >*<
1893+ toJ j >*<
1894+ toK k
1895+ {-# INLINE liftToEncoding2 #-}
1896+
1897+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) where
1898+ liftToJSON = liftToJSON2 toJSON toJSONList
1899+ {-# INLINE liftToJSON #-}
1900+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1901+ {-# INLINE liftToEncoding #-}
1902+
1903+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON (a, b, c, d, e, f, g, h, i, j, k) where
1904+ toJSON = toJSON2
1905+ {-# INLINE toJSON #-}
1906+ toEncoding = toEncoding2
1907+ {-# INLINE toEncoding #-}
1908+
1909+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) where
1910+ liftToJSON2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = Array $ V.create $ do
1911+ mv <- VM.unsafeNew 12
1912+ VM.unsafeWrite mv 0 (toJSON a)
1913+ VM.unsafeWrite mv 1 (toJSON b)
1914+ VM.unsafeWrite mv 2 (toJSON c)
1915+ VM.unsafeWrite mv 3 (toJSON d)
1916+ VM.unsafeWrite mv 4 (toJSON e)
1917+ VM.unsafeWrite mv 5 (toJSON f)
1918+ VM.unsafeWrite mv 6 (toJSON g)
1919+ VM.unsafeWrite mv 7 (toJSON h)
1920+ VM.unsafeWrite mv 8 (toJSON i)
1921+ VM.unsafeWrite mv 9 (toJSON j)
1922+ VM.unsafeWrite mv 10 (toK k)
1923+ VM.unsafeWrite mv 11 (toL l)
1924+ return mv
1925+ {-# INLINE liftToJSON2 #-}
1926+
1927+ liftToEncoding2 toK _ toL _ (a, b, c, d, e, f, g, h, i, j, k, l) = tuple $
1928+ toEncoding a >*<
1929+ toEncoding b >*<
1930+ toEncoding c >*<
1931+ toEncoding d >*<
1932+ toEncoding e >*<
1933+ toEncoding f >*<
1934+ toEncoding g >*<
1935+ toEncoding h >*<
1936+ toEncoding i >*<
1937+ toEncoding j >*<
1938+ toK k >*<
1939+ toL l
1940+ {-# INLINE liftToEncoding2 #-}
1941+
1942+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) where
1943+ liftToJSON = liftToJSON2 toJSON toJSONList
1944+ {-# INLINE liftToJSON #-}
1945+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1946+ {-# INLINE liftToEncoding #-}
1947+
1948+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l) where
1949+ toJSON = toJSON2
1950+ {-# INLINE toJSON #-}
1951+ toEncoding = toEncoding2
1952+ {-# INLINE toEncoding #-}
1953+
1954+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) where
1955+ liftToJSON2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = Array $ V.create $ do
1956+ mv <- VM.unsafeNew 13
1957+ VM.unsafeWrite mv 0 (toJSON a)
1958+ VM.unsafeWrite mv 1 (toJSON b)
1959+ VM.unsafeWrite mv 2 (toJSON c)
1960+ VM.unsafeWrite mv 3 (toJSON d)
1961+ VM.unsafeWrite mv 4 (toJSON e)
1962+ VM.unsafeWrite mv 5 (toJSON f)
1963+ VM.unsafeWrite mv 6 (toJSON g)
1964+ VM.unsafeWrite mv 7 (toJSON h)
1965+ VM.unsafeWrite mv 8 (toJSON i)
1966+ VM.unsafeWrite mv 9 (toJSON j)
1967+ VM.unsafeWrite mv 10 (toJSON k)
1968+ VM.unsafeWrite mv 11 (toL l)
1969+ VM.unsafeWrite mv 12 (toM m)
1970+ return mv
1971+ {-# INLINE liftToJSON2 #-}
1972+
1973+ liftToEncoding2 toL _ toM _ (a, b, c, d, e, f, g, h, i, j, k, l, m) = tuple $
1974+ toEncoding a >*<
1975+ toEncoding b >*<
1976+ toEncoding c >*<
1977+ toEncoding d >*<
1978+ toEncoding e >*<
1979+ toEncoding f >*<
1980+ toEncoding g >*<
1981+ toEncoding h >*<
1982+ toEncoding i >*<
1983+ toEncoding j >*<
1984+ toEncoding k >*<
1985+ toL l >*<
1986+ toM m
1987+ {-# INLINE liftToEncoding2 #-}
1988+
1989+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) where
1990+ liftToJSON = liftToJSON2 toJSON toJSONList
1991+ {-# INLINE liftToJSON #-}
1992+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
1993+ {-# INLINE liftToEncoding #-}
1994+
1995+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m) where
1996+ toJSON = toJSON2
1997+ {-# INLINE toJSON #-}
1998+ toEncoding = toEncoding2
1999+ {-# INLINE toEncoding #-}
2000+
2001+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) where
2002+ liftToJSON2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = Array $ V.create $ do
2003+ mv <- VM.unsafeNew 14
2004+ VM.unsafeWrite mv 0 (toJSON a)
2005+ VM.unsafeWrite mv 1 (toJSON b)
2006+ VM.unsafeWrite mv 2 (toJSON c)
2007+ VM.unsafeWrite mv 3 (toJSON d)
2008+ VM.unsafeWrite mv 4 (toJSON e)
2009+ VM.unsafeWrite mv 5 (toJSON f)
2010+ VM.unsafeWrite mv 6 (toJSON g)
2011+ VM.unsafeWrite mv 7 (toJSON h)
2012+ VM.unsafeWrite mv 8 (toJSON i)
2013+ VM.unsafeWrite mv 9 (toJSON j)
2014+ VM.unsafeWrite mv 10 (toJSON k)
2015+ VM.unsafeWrite mv 11 (toJSON l)
2016+ VM.unsafeWrite mv 12 (toM m)
2017+ VM.unsafeWrite mv 13 (toN n)
2018+ return mv
2019+ {-# INLINE liftToJSON2 #-}
2020+
2021+ liftToEncoding2 toM _ toN _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) = tuple $
2022+ toEncoding a >*<
2023+ toEncoding b >*<
2024+ toEncoding c >*<
2025+ toEncoding d >*<
2026+ toEncoding e >*<
2027+ toEncoding f >*<
2028+ toEncoding g >*<
2029+ toEncoding h >*<
2030+ toEncoding i >*<
2031+ toEncoding j >*<
2032+ toEncoding k >*<
2033+ toEncoding l >*<
2034+ toM m >*<
2035+ toN n
2036+ {-# INLINE liftToEncoding2 #-}
2037+
2038+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
2039+ liftToJSON = liftToJSON2 toJSON toJSONList
2040+ {-# INLINE liftToJSON #-}
2041+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
2042+ {-# INLINE liftToEncoding #-}
2043+
2044+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) where
2045+ toJSON = toJSON2
2046+ {-# INLINE toJSON #-}
2047+ toEncoding = toEncoding2
2048+ {-# INLINE toEncoding #-}
2049+
2050+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) where
2051+ liftToJSON2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = Array $ V.create $ do
2052+ mv <- VM.unsafeNew 15
2053+ VM.unsafeWrite mv 0 (toJSON a)
2054+ VM.unsafeWrite mv 1 (toJSON b)
2055+ VM.unsafeWrite mv 2 (toJSON c)
2056+ VM.unsafeWrite mv 3 (toJSON d)
2057+ VM.unsafeWrite mv 4 (toJSON e)
2058+ VM.unsafeWrite mv 5 (toJSON f)
2059+ VM.unsafeWrite mv 6 (toJSON g)
2060+ VM.unsafeWrite mv 7 (toJSON h)
2061+ VM.unsafeWrite mv 8 (toJSON i)
2062+ VM.unsafeWrite mv 9 (toJSON j)
2063+ VM.unsafeWrite mv 10 (toJSON k)
2064+ VM.unsafeWrite mv 11 (toJSON l)
2065+ VM.unsafeWrite mv 12 (toJSON m)
2066+ VM.unsafeWrite mv 13 (toN n)
2067+ VM.unsafeWrite mv 14 (toO o)
2068+ return mv
2069+ {-# INLINE liftToJSON2 #-}
2070+
2071+ liftToEncoding2 toN _ toO _ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) = tuple $
2072+ toEncoding a >*<
2073+ toEncoding b >*<
2074+ toEncoding c >*<
2075+ toEncoding d >*<
2076+ toEncoding e >*<
2077+ toEncoding f >*<
2078+ toEncoding g >*<
2079+ toEncoding h >*<
2080+ toEncoding i >*<
2081+ toEncoding j >*<
2082+ toEncoding k >*<
2083+ toEncoding l >*<
2084+ toEncoding m >*<
2085+ toN n >*<
2086+ toO o
2087+ {-# INLINE liftToEncoding2 #-}
2088+
2089+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) where
2090+ liftToJSON = liftToJSON2 toJSON toJSONList
2091+ {-# INLINE liftToJSON #-}
2092+ liftToEncoding = liftToEncoding2 toEncoding toEncodingList
2093+ {-# INLINE liftToEncoding #-}
2094+
2095+instance (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n, ToJSON o) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) where
2096+ toJSON = toJSON2
2097+ {-# INLINE toJSON #-}
2098+ toEncoding = toEncoding2
2099+ {-# INLINE toEncoding #-}