@@ -15,10 +15,10 @@ import Instances ()
1515
1616import Control.Applicative (Const(..))
1717import Control.Monad (forM)
18−import Data.Aeson (FromJSONKeyFunction(..), FromJSONKey(..), decode, eitherDecode, encode, genericParseJSON, genericToJSON, genericToEncoding, object, FromJSON(..), withObject, (.=), (.:), (.:?), (.:!))
18+import Data.Aeson (FromJSONKeyFunction(..), FromJSONKey(..), decode, eitherDecode, encode, genericParseJSON, genericToJSON, genericToEncoding, object, FromJSON(..), withObject, ToJSON1(..), (.=), (.:), (.:?), (.:!))
1919import Data.Aeson.Text (encodeToTextBuilder)
2020import Data.Aeson.Internal (JSONPathElement(..), formatError)
21−import Data.Aeson.TH (deriveJSON)
21+import Data.Aeson.TH (deriveJSON, deriveToJSON, deriveToJSON1)
2222import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields, Options(..), SumEncoding(..))
2323import Data.Char (toUpper)
2424import Data.Hashable (hash)
@@ -93,6 +93,9 @@ tests = testGroup "unit" [
9393 , testGroup "Issue #351" $ fmap (testCase "-") issue351
9494 , testGroup "Nullary constructors" $ fmap (testCase "-") nullaryConstructors
9595 , testGroup "FromJSONKey" $ fmap (testCase "-") fromJSONKeyAssertions
96+ , testGroup "PR #455" [
97+ testCase "-" pr455
98+ ]
9699 ]
97100
98101roundTripCamel :: String -> Assertion
@@ -544,10 +547,24 @@ encoderComparisonTests = do
544547
545548-- A regression test for: https://github.com/bos/aeson/issues/293
546549data MyRecord = MyRecord {_field1 :: Maybe Int, _field2 :: Maybe Bool}
547−deriveJSON defaultOptions{omitNothingFields=True} ''MyRecord
548550
549551data MyRecord2 = MyRecord2 {_field3 :: Maybe Int, _field4 :: Maybe Bool}
550552 deriving Generic
551553
552554instance ToJSON MyRecord2
553555instance FromJSON MyRecord2
556+
557+-- A regression test for: https://github.com/bos/aeson/pull/455
558+data Foo a = FooNil | FooCons (Foo Int)
559+
560+pr455 :: Assertion
561+pr455 = assertEqual "FooCons FooNil"
562+ (toJSON foo) (liftToJSON undefined undefined foo)
563+ where
564+ foo :: Foo Int
565+ foo = FooCons FooNil
566+
567+deriveJSON defaultOptions{omitNothingFields=True} ''MyRecord
568+
569+deriveToJSON defaultOptions ''Foo
570+deriveToJSON1 defaultOptions ''Foo