Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode does not resolve ambiguity between string and numeric values #22

Closed
nikita-volkov opened this issue Jan 26, 2013 · 4 comments
Closed

Comments

@nikita-volkov
Copy link

This one is related to #20.

{-# 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.

There are two ways of solving this:

  1. Resolve the Parsing result type is not dictated by the output type #20
  2. Put the ambiguous string values in quotes

I again vote for the first way.

@snoyberg
Copy link
Owner

#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).

@nikita-volkov
Copy link
Author

Okay, I understand you

@ellis
Copy link

ellis commented Jan 19, 2014

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.

@snoyberg
Copy link
Owner

Handled by Data.Yaml.Parser module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants