From 5379bfdfb4ad885860d02b35bc2f50f8f45e037a Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Mon, 24 Apr 2017 15:41:52 +0100 Subject: [PATCH] Revert `Maybe` codec change --- src/Data/Argonaut/Decode/Class.purs | 15 +++------------ src/Data/Argonaut/Encode/Class.purs | 8 ++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Data/Argonaut/Decode/Class.purs b/src/Data/Argonaut/Decode/Class.purs index 67f93b6..6ff21d2 100644 --- a/src/Data/Argonaut/Decode/Class.purs +++ b/src/Data/Argonaut/Decode/Class.purs @@ -21,18 +21,9 @@ class DecodeJson a where decodeJson :: Json -> Either String a instance decodeJsonMaybe :: DecodeJson a => DecodeJson (Maybe a) where - decodeJson j = - case decode j of - Right x -> Right x - Left x -> backwardsCompat - where - decode = - decodeJObject >=> lookupJust >=> decodeJson - lookupJust = - maybe (Left "Missing property 'just'") Right <<< SM.lookup "just" - backwardsCompat - | isNull j = pure Nothing - | otherwise = Just <$> decodeJson j + decodeJson j + | isNull j = pure Nothing + | otherwise = Just <$> decodeJson j instance decodeJsonTuple :: (DecodeJson a, DecodeJson b) => DecodeJson (Tuple a b) where decodeJson j = decodeJson j >>= f diff --git a/src/Data/Argonaut/Encode/Class.purs b/src/Data/Argonaut/Encode/Class.purs index fa8d88c..068dff0 100644 --- a/src/Data/Argonaut/Encode/Class.purs +++ b/src/Data/Argonaut/Encode/Class.purs @@ -2,8 +2,8 @@ module Data.Argonaut.Encode.Class where import Prelude -import Data.Argonaut.Core (Json(), jsonNull, fromBoolean, fromNumber, fromString, fromArray, fromObject, jsonEmptyObject, jsonSingletonObject) -import Data.Either (Either(), either) +import Data.Argonaut.Core (Json, fromArray, fromBoolean, fromNumber, fromObject, fromString, jsonNull) +import Data.Either (Either, either) import Data.Int (toNumber) import Data.List (List(..), (:), toUnfoldable) import Data.Map as M @@ -16,8 +16,8 @@ class EncodeJson a where encodeJson :: a -> Json instance encodeJsonMaybe :: EncodeJson a => EncodeJson (Maybe a) where - encodeJson Nothing = jsonEmptyObject - encodeJson (Just a) = jsonSingletonObject "just" (encodeJson a) + encodeJson Nothing = jsonNull + encodeJson (Just a) = encodeJson a instance encodeJsonTuple :: (EncodeJson a, EncodeJson b) => EncodeJson (Tuple a b) where encodeJson (Tuple a b) = encodeJson [encodeJson a, encodeJson b]