Skip to content

Commit dc778b2

Browse files
authored
Merge pull request #30 from purescript-contrib/maybe-codec
Revert `Maybe` codec change
2 parents 41d4048 + 5379bfd commit dc778b2

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/Data/Argonaut/Decode/Class.purs

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,9 @@ class DecodeJson a where
2121
decodeJson :: Json -> Either String a
2222

2323
instance decodeJsonMaybe :: DecodeJson a => DecodeJson (Maybe a) where
24-
decodeJson j =
25-
case decode j of
26-
Right x -> Right x
27-
Left x -> backwardsCompat
28-
where
29-
decode =
30-
decodeJObject >=> lookupJust >=> decodeJson
31-
lookupJust =
32-
maybe (Left "Missing property 'just'") Right <<< SM.lookup "just"
33-
backwardsCompat
34-
| isNull j = pure Nothing
35-
| otherwise = Just <$> decodeJson j
24+
decodeJson j
25+
| isNull j = pure Nothing
26+
| otherwise = Just <$> decodeJson j
3627

3728
instance decodeJsonTuple :: (DecodeJson a, DecodeJson b) => DecodeJson (Tuple a b) where
3829
decodeJson j = decodeJson j >>= f

src/Data/Argonaut/Encode/Class.purs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Data.Argonaut.Encode.Class where
22

33
import Prelude
44

5-
import Data.Argonaut.Core (Json(), jsonNull, fromBoolean, fromNumber, fromString, fromArray, fromObject, jsonEmptyObject, jsonSingletonObject)
6-
import Data.Either (Either(), either)
5+
import Data.Argonaut.Core (Json, fromArray, fromBoolean, fromNumber, fromObject, fromString, jsonNull)
6+
import Data.Either (Either, either)
77
import Data.Int (toNumber)
88
import Data.List (List(..), (:), toUnfoldable)
99
import Data.Map as M
@@ -16,8 +16,8 @@ class EncodeJson a where
1616
encodeJson :: a -> Json
1717

1818
instance encodeJsonMaybe :: EncodeJson a => EncodeJson (Maybe a) where
19-
encodeJson Nothing = jsonEmptyObject
20-
encodeJson (Just a) = jsonSingletonObject "just" (encodeJson a)
19+
encodeJson Nothing = jsonNull
20+
encodeJson (Just a) = encodeJson a
2121

2222
instance encodeJsonTuple :: (EncodeJson a, EncodeJson b) => EncodeJson (Tuple a b) where
2323
encodeJson (Tuple a b) = encodeJson [encodeJson a, encodeJson b]

0 commit comments

Comments
 (0)