on master help sign in
Add instances of ToJSON and FromJSON for Ordering
commitc85c2d14028bbc5bd810e154a84203ce6cfcb43a authorCale Gibbard <cgibbard@gmail.com> dateWed 25 Nov 2015, 15:28 (11 years ago) parent4667ef1
1 file changed+15
Data/Aeson/Types/Instances.hs+15
Data/Aeson/Types/Instances.hs+15
@@ -182,6 +182,21 @@ instance FromJSON Bool where
182182 parseJSON = withBool "Bool" pure
183183 {-# INLINE parseJSON #-}
184184
185+instance ToJSON Ordering where
186+ toJSON o = String $ case o of
187+ LT -> "LT"
188+ EQ -> "EQ"
189+ GT -> "GT"
190+
191+instance FromJSON Ordering where
192+ parseJSON v = case v of
193+ String s -> case s of
194+ "LT" -> return LT
195+ "EQ" -> return EQ
196+ "GT" -> return GT
197+ _ -> fail "Parsing Ordering value failed: expected \"LT\", \"EQ\", or \"GT\""
198+ _ -> typeMismatch "Ordering" v
199+
185200instance ToJSON () where
186201 toJSON _ = emptyArray
187202 {-# INLINE toJSON #-}