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

Comments

Projects
None yet
3 participants
@nikita-volkov

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 #20
  2. Put the ambiguous string values in quotes

I again vote for the first way.

@snoyberg

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Jan 27, 2013

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

Owner

snoyberg commented Jan 27, 2013

#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

This comment has been minimized.

Show comment
Hide comment
@nikita-volkov

nikita-volkov Jan 27, 2013

Okay, I understand you

Okay, I understand you

@ellis

This comment has been minimized.

Show comment
Hide comment
@ellis

ellis 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.

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

This comment has been minimized.

Show comment
Hide comment
@snoyberg

snoyberg Aug 29, 2014

Owner

Handled by Data.Yaml.Parser module.

Owner

snoyberg commented Aug 29, 2014

Handled by Data.Yaml.Parser module.

@snoyberg snoyberg closed this Aug 29, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment