From 89203d06306905ab9bfa12761d8980cd9da28229 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 9 May 2013 08:39:06 +0300 Subject: [PATCH] returnJson and provideJson --- yesod-core/Yesod/Core/Json.hs | 20 +++++++++++++++++++- yesod-core/yesod-core.cabal | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/yesod-core/Yesod/Core/Json.hs b/yesod-core/Yesod/Core/Json.hs index 94fcbcfb..84550605 100644 --- a/yesod-core/Yesod/Core/Json.hs +++ b/yesod-core/Yesod/Core/Json.hs @@ -4,6 +4,8 @@ module Yesod.Core.Json ( -- * Convert from a JSON value defaultLayoutJson , jsonToRepJson + , returnJson + , provideJson -- * Convert to a JSON value , parseJsonBody @@ -23,7 +25,9 @@ module Yesod.Core.Json , acceptsJson ) where -import Yesod.Core.Handler (HandlerT, getRequest, invalidArgs, redirect, selectRep, provideRep, rawRequestBody) +import Yesod.Core.Handler (HandlerT, getRequest, invalidArgs, redirect, selectRep, provideRep, rawRequestBody, ProvidedRep) +import Control.Monad.Trans.Writer (Writer) +import Data.Monoid (Endo) import Yesod.Core.Content (TypedContent) import Yesod.Core.Types (reqAccept) import Yesod.Core.Class.Yesod (defaultLayout, Yesod) @@ -60,6 +64,20 @@ defaultLayoutJson w json = selectRep $ do -- /Since: 0.3.0/ jsonToRepJson :: (Monad m, J.ToJSON a) => a -> m J.Value jsonToRepJson = return . J.toJSON +{-# DEPRECATED jsonToRepJson "Use returnJson instead" #-} + +-- | Convert a value to a JSON representation via aeson\'s 'J.toJSON' function. +-- +-- Since 1.2.1 +returnJson :: (Monad m, J.ToJSON a) => a -> m J.Value +returnJson = return . J.toJSON + +-- | Provide a JSON representation for usage with 'selectReps', using aeson\'s +-- 'J.toJSON' function to perform the conversion. +-- +-- Since 1.2.1 +provideJson :: (Monad m, J.ToJSON a) => a -> Writer (Endo [ProvidedRep m]) () +provideJson = provideRep . return . J.toJSON -- | Parse the request body to a data type as a JSON value. The -- data type must support conversion from JSON via 'J.FromJSON'. diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index a3511872..9b9126de 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -1,5 +1,5 @@ name: yesod-core -version: 1.2.0.4 +version: 1.2.1 license: MIT license-file: LICENSE author: Michael Snoyman