Closed
Description
Here's the minimal example to reproduce:
newtype Foo = Foo
{fooId :: Int
,bazList :: List Baz
}
instance decodeJsonFoo :: DecodeJson Foo where
decodeJson json = do
obj <- decodeJson json
id <- obj .? "fooId"
bs <- obj .? "bazList"
pure $ Foo { fooId: id
, bazList : bs}
newtype Baz = Baz
{bazId :: Int
,bazOpt :: Maybe Int
}
instance decodeJsonBaz :: DecodeJson Baz where
decodeJson json = do
obj <- decodeJson json
bId <- obj .? "bazId"
bad <- obj .?? "bazOpt"
good <- foldJsonNumber Nothing (Just <<< floor) <$> obj .? "bazOpt"
pure $ Baz { bazId: bId
, bazOpt: bad
}
When each Baz in the list has Int value in bazOpt then "bad" works fine.
When some Bazes in the list has null in bazOpt field then "bad" give this error:
Couldn't decode List Value is not a Number.
"good" works fine even with nulls.
is getFieldOptional broken?
Metadata
Metadata
Assignees
Labels
No labels