Skip to content

Unexpected counterexample to decode . encode = Just #24

@meiersi

Description

@meiersi

Using yaml-0.8.2.1 imported as Y

*Schiller> Y.encode ( [""] :: [String])
"- \n"
*Schiller> Y.decode $ Y.encode ( [""] :: [String]) :: Maybe [String]
Nothing

The problem seems to be the encoding of the empty string without any quotes.

*Schiller> Y.encode ( ["a"] :: [String])
"- a\n"
*Schiller> Y.decode $ Y.encode ( ["a"] :: [String]) :: Maybe [String]
Just ["a"]
*Schiller> 

I don't know YAML well, but this is unexpected. Using aeson, imported as A, the result looks as expected.

*Schiller> A.encode ( [""] :: [String])
Chunk "[\"\"]" Empty
*Schiller> A.decode $ A.encode ( [""] :: [String]) :: Maybe [String]
Just [""]
*Schiller> 

It is thus not one of the pitfalls (http://hackage.haskell.org/packages/archive/aeson/0.6.1.0/doc/html/Data-Aeson.html#g:6) that one has to know about when using aeson.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions