Skip to content

Commit 80ec09c

Browse files
authored
Merge pull request #874 from haskell/unit-proxy-deserialize
Accept all values in FromJSON () and FromJSON (Proxy tag)
2 parents 0d88558 + 677daf0 commit 80ec09c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ For the latest version of this document, please see [https://github.com/haskell/
1818
* `Double` and `Float` infinities are encoded as `"+inf"` and `"-inf"`.
1919
Change `To/FromJSONKey` instances to use `"+inf"` and `"-inf"` too.
2020

21+
* `FromJSON ()` and `FromJSON (Proxy tag)` accept any JSON value.
22+
2123
### 1.5.6.0
2224
* Make `Show Value` instance print object keys in lexicographic order.
2325

src/Data/Aeson/Types/FromJSON.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,7 @@ instance FromJSON Ordering where
15271527
" (expected \"LT\", \"EQ\", or \"GT\")"
15281528

15291529
instance FromJSON () where
1530-
parseJSON = withArray "()" $ \v ->
1531-
if V.null v
1532-
then pure ()
1533-
else prependContext "()" $ fail "expected an empty array"
1530+
parseJSON _ = pure ()
15341531

15351532
instance FromJSON Char where
15361533
parseJSON = withText "Char" parseChar
@@ -2283,10 +2280,10 @@ instance FromJSON1 S.Maybe where
22832280
-------------------------------------------------------------------------------
22842281

22852282
instance FromJSON1 Proxy where
2286-
liftParseJSON _ _ = fromNull "Proxy" Proxy
2283+
liftParseJSON _ _ _ = pure Proxy
22872284

22882285
instance FromJSON (Proxy a) where
2289-
parseJSON = fromNull "Proxy" Proxy
2286+
parseJSON _ = pure Proxy
22902287

22912288
fromNull :: String -> a -> Value -> Parser a
22922289
fromNull _ a Null = pure a

0 commit comments

Comments
 (0)