You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Data.Yaml
import GHC.Generics (Generic)
data A = A { phone :: String }
deriving (Generic, Show)
instance ToJSON A
instance FromJSON A
main = do
print $ encode $ A "+72304234342"
print $ (decode $ encode $ A "+72304234342" :: Maybe A)
outputs:
"phone: +72304234342\n"
Nothing
As you can see the decode parser fails on the result of encode.
#20 would require a complete overhaul of the encoding/decoding situation. It's not really a solution, it's creating a new system. For my own uses (and I think many others), the convenience of ToJSON/FromJSON isn't something we're going to give up on. But there's nothing stopping you from having your own ToYAML/FromYAML typeclasses.
Meanwhile, I think it's worth looking at option (2).
Here's my vote to do something about this. The issue makes the yaml library unusable for me, because files which are written cannot be read back if they contain strings properties which happen to be even somewhat numeric. UTCTime is another type which can't be read back once written.
The same data can be written and read back when using Aeson.encode, but not with the yaml library.
This one is related to #20.
outputs:
As you can see the
decode
parser fails on the result ofencode
.There are two ways of solving this:
I again vote for the first way.
The text was updated successfully, but these errors were encountered: