@@ -79,6 +79,8 @@ import Data.Time.Format (FormatTime, formatTime, parseTime)
7979import Data.Traversable as Tr (sequence)
8080import Data.Vector (Vector)
8181import Data.Word (Word8, Word16, Word32, Word64)
82+import Data.Version (Version, showVersion, parseVersion)
83+import Text.ParserCombinators.ReadP (readP_to_S)
8284import Foreign.Storable (Storable)
8385import Prelude hiding (foldr)
8486import qualified Data.Aeson.Encode.Builder as E
@@ -1466,6 +1468,18 @@ instance FromJSON a => FromJSON (Last a) where
14661468 parseJSON = fmap Last . parseJSON
14671469 {-# INLINE parseJSON #-}
14681470
1471+instance ToJSON Version where
1472+ toJSON = toJSON . showVersion
1473+ {-# INLINE toJSON #-}
1474+
1475+instance FromJSON Version where
1476+ {-# INLINE parseJSON #-}
1477+ parseJSON = withText "Version" $ go . readP_to_S parseVersion . unpack
1478+ where
1479+ go [(v,_)] = return v
1480+ go (_ : xs) = go xs
1481+ go _ = fail $ "could not parse Version"
1482+
14691483-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
14701484-- and fails using @'typeMismatch' expected@ otherwise.
14711485withObject :: String -> (Object -> Parser a) -> Value -> Parser a