1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Define a JSONFields bridge for ToJSON instances.

This commit is contained in:
Rob Rix 2017-09-10 22:31:57 -04:00
parent 8c205e7114
commit f43dc62d12

View File

@ -28,3 +28,10 @@ instance (Apply1 Foldable fs) => ToJSONFields1 (Union fs) where
instance (ToJSON a, ToJSON b) => ToJSONFields (a, b) where
toJSONFields (a, b) = [ "before" .= a, "after" .= b ]
newtype JSONFields a = JSONFields { unJSONFields :: a }
instance (ToJSONFields a) => ToJSON (JSONFields a) where
toJSON = object . toJSONFields . unJSONFields
toEncoding = pairs . mconcat . toJSONFields . unJSONFields