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
{{ message }}
Repository navigation
Breaking changes on 0.10 regarding Null field parsing on Maybe types #287
Can we keep the existing operator (.:?) with 0.9.0 behavior, and as @gregwebs recommends, add a (.:??) operator for this new behavior ? ( as proposed by @lykahb in #83 )
You use a wrong operator. Field val has type Maybe String. In the return value of the (.:?)Maybe is related only to the presence of the key. The operator has never not handled nulls. The key exists so it tries to convert null into String.
If the key val is mandatory, you can use (.:). If it is optional, fmap join (o .:? "val") will use the right FromJSON instance.
@lykahb I see, so previously fmap join (o .:? "val") was the default behavior (Null would be coerced into Nothing). Null and key existence were conflated. Now it's separate. Cool.
Maybe is related only to the presence of the key
In 0.10 yes, in 0.9 it could be related to the value too, right? Example below.
newtypeA=A{val::MaybeString}derivingShow
λ: instance FromJSONAwhere parseJSON (Object o) =A<$> o .:"val"
λ: eitherDecode "{ \"val\" : null }"::EitherStringARight (A {val =Nothing})
Hi,
Just to add my 5 cents; (.??) is a part of the original proposal to add one extra constructor to the Value type (eg. https://github.com/tolysz/aeson/blob/MissingDefault2/examples/Possible.hs)
And really there is no other way around.
I've been keeping quiet but types Maybe and Maybe Maybe have different universal properties and sure you can hack around adding extra information on creation of From/ToJSON to cater for a difference but it will never be generic i.e. encodable in the type system by storing all information needed to present this data.
My Original proposal was:
toJson (Nothing :: Maybe a) = Null
toJson (Just a :: Maybe a) = toJson a
toJson (Nothing :: Maybe (Maybe a)) = Missing -- extra constructor
toJson (Just Nothing :: Maybe (Maybe a)) = Null
toJson (Just (Just a) :: Maybe (Maybe a)) = toJson a
-- or Equivalent
toJson (MissingData :: Possible a) = Missing -- extra constructor
toJson (HaveHull :: Possible a) = Null
toJson ((HaveData a) :: Possible a) = toJson a
Activity
dmjio commentedon Sep 19, 2015
Seems like this is the culprit, d0414be
Can we keep the existing operator
(.:?)with0.9.0behavior, and as @gregwebs recommends, add a(.:??)operator for this new behavior ? ( as proposed by @lykahb in #83 )lykahb commentedon Sep 19, 2015
You use a wrong operator. Field val has type
Maybe String. In the return value of the(.:?)Maybeis related only to the presence of the key. The operator has never not handled nulls. The key exists so it tries to convert null intoString.If the key val is mandatory, you can use
(.:). If it is optional,fmap join (o .:? "val")will use the right FromJSON instance.dmjio commentedon Sep 19, 2015
@lykahb I see, so previously
fmap join (o .:? "val")was the default behavior (Nullwould be coerced intoNothing).Nulland key existence were conflated. Now it's separate. Cool.In
0.10yes, in0.9it could be related to the value too, right? Example below.dmjio commentedon Sep 19, 2015
Here's a list of the old and new differences. http://lpaste.net/141286
MaxGabriel commentedon Sep 21, 2015
This is a major breaking change; I'd echo @gregwebs request that this be in the changelog or maybe use a different operator.
tolysz commentedon Oct 11, 2015
Hi,
Just to add my 5 cents;
(.??)is a part of the original proposal to add one extra constructor to the Value type (eg. https://github.com/tolysz/aeson/blob/MissingDefault2/examples/Possible.hs)And really there is no other way around.
I've been keeping quiet but types
MaybeandMaybe Maybehave different universal properties and sure you can hack around adding extra information on creation ofFrom/ToJSONto cater for a difference but it will never begenerici.e. encodable in the type system by storing all information needed to present this data.My Original proposal was:
This gives you some very nice properties: eg. the
toJson aallows typeato decide on how it should present itself and thus easily build APIs eg. https://github.com/tolysz/google-api/blob/master/src/Network/Google/Api/Kinds.hswhere I do not need to specialise
ListResponseto include HACK to show/hide fields it at times.sapek commentedon Nov 11, 2015
@lykahb, this also seems to work in 0.10:
Is this a valid option to get old behavior or do I need to use
fmap join (o .:? "val")?lykahb commentedon Nov 12, 2015
@sapek Yes, they should have the same behavior.
nikomi commentedon Dec 14, 2015
I would +1 pull #288 - is anything happening with this thread?
tolysz commentedon Dec 15, 2015
This is sorted by: #326
I.e. the original question I mean. Simply one pattern got lost in the upgrade; Api does not change.
nikomi commentedon Dec 15, 2015
thanx for info!
Pull request #326 does not seem to be merged into master yet - any idea when this might be released?
tolysz commentedon Dec 15, 2015
I use
stack; but I agree it prevents people from using 0.10 in the wild; and the sooner the better.With this patch it simply builds all packages :)
hvr commentedon Dec 20, 2015
@bos bump
Work around haskell/aeson#287 (fixes #1570)
bos commentedon Jan 20, 2016
I believe this should now be fixed.
Relax aeson upper bound