Decoding a Map with a Maybe value fails #72

Closed
da-x opened this Issue Mar 9, 2012 · 3 comments

Comments

Projects
None yet
3 participants

da-x commented Mar 9, 2012

I'm using 0.6.0.0 with GHC 7.4.1 on Linux x86_64.

Here's a very basic 'encode' + 'decode' chain that fails:

import Data.Aeson.Generic (decode, encode)
import qualified Data.Map as Map
import Data.Map (Map)

type SomeType = Map String (Maybe String)

main :: IO ()
main = do
  let x = ((Map.fromList [("x", Nothing)]) :: SomeType)
  let y = (decode (encode x) :: Maybe SomeType)
  if (Just x /= y) then
      error "Bug"
    else
      print "OK"

da-x commented Mar 9, 2012

Also, in 0.5.0.0 this problem is not there, so I guess it has something to do with the changes from 0.5.0.0 to 0.6.0.0.

Contributor

jhance commented Mar 18, 2012

Broken by 49befca - I'm investigating this right now

Owner

bos commented Jun 16, 2012

@basvandijk - this looks like something you might know about?

bos closed this in 7639ea8 Nov 20, 2012

@bos bos added a commit that referenced this issue Nov 20, 2012

@bos bos Add a test case for gh-72 80e5147

@tolysz tolysz pushed a commit to tolysz/aeson that referenced this issue May 18, 2015

@jhance jhance Fix #72.
Sometimes, it appears, Nullary constructors can be encoded as Null as
well as an empty array [not sure why one this!]. The Generic code, as of
49befca, fails when a Null is
passed for a nullary constructor. Add in a pattern match to fix this
issue.
c3a1741

@tolysz tolysz pushed a commit to tolysz/aeson that referenced this issue May 18, 2015

@bos bos Add a test case for gh-72 c2485e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment