Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Unexpected behavior of .:? #83

Open
lykahb opened this Issue · 2 comments

2 participants

Boris Lykah Bryan O'Sullivan
Boris Lykah

I want to have distinction between absence of field and its null value.

data Blah = Blah (Maybe (Maybe String))
instance FromJSON Blah where
  parseJSON (Object v) = Blah <$> v .:? "blah"
Blah Nothing -- if field not mentioned
Blah (Just Nothing) -- if field has null value

However, the result of parsing is never Blah (Just Nothing) because .:? uses (Maybe a) instance directly.

(.:?) :: (FromJSON a) => Object -> Text -> Parser (Maybe a)
obj .:? key = case H.lookup key obj of
               Nothing -> pure Nothing
               Just v  -> parseJSON v
            -- Just v  -> Just <$> parseJSON v would have expected behavior
Bryan O'Sullivan
Owner
bos commented

The obvious fix for this breaks some of the test suite, and I haven't had a chance to diagnose that yet. Looking.

Bryan O'Sullivan
Owner
bos commented

cc @ffwng

Boris Lykah lykahb referenced this issue from a commit in lykahb/aeson
Boris Lykah Fix .:? behavior for #83 5ae3d04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.