--[[----------------------------------------------------------------------------

KSJsonEncoder.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2011 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

local rapidjson = require 'rapidjson'

local json_null = rapidjson.null

--============================================================================--
-- @mark KSJsonEncoder namespace

--[[!

	\class KSJsonEncoder

	\brief This namespace provides translation utilities between JSON-encoded
		REST request contents and the Lua structures used by the LUA API calls.
		
		These functions are typically used as the translation functions for
		\c mapB calls.

]]--

local KSJsonEncoder = {
	json_null = json_null
}

--------------------------------------------------------------------------------
--[[!
     \brief Translates a Lua-object string into the equivalent JSON data structure.

     \param luaObject The Lua-object string.
	 \param optArg An optional Lua-table specifying JSON encoding formating options
	  		{ 
				"pretty", (boolean)
				"sort_keys", (boolean)
				"empty_table_as_array", (boolean)
				"max_depth" (int)
			}
 
     \return The JSON string.
]]--

function KSJsonEncoder.encodeWebSafeJson( --[[string]] luaObject, optArg )
	
	local result = rapidjson.encode( luaObject, optArg )
	
	return "while (1) {}\n" .. result
	 
end

--------------------------------------------------------------------------------

--[[!
     \brief Translates a Lua-object string into the equivalent JSON data structure,
     	adding whitespace for readability.

     \param luaObject The Lua-object string.
	 \param optArg An optional Lua-table specifying JSON encoding formating options
	  		{ 
				"pretty", (boolean)
				"sort_keys", (boolean)
				"empty_table_as_array", (boolean)
				"max_depth" (int)
			}
     \return The JSON string.
]]--

function KSJsonEncoder.prettyPrint( --[[string]] luaObject, optArg )

	return rapidjson.encode( luaObject, optArg )

end

--------------------------------------------------------------------------------

--[[!
     \brief Translates a Lua-object string into the equivalent JSON data structure
     	that is specifically suitable for Oz upload operations.

     \param luaObject The Lua-object string.
	 \param optArg An optional Lua-table specifying JSON encoding formating options
	  		{ 
				"pretty", (boolean)
				"sort_keys", (boolean)
				"empty_table_as_array", (boolean)
				"max_depth" (int)
			}
 
     \return The JSON string.
]]--

function KSJsonEncoder.encodeOzUploadJson( --[[string]] luaObject, optArg )
	
	return rapidjson.encode( luaObject, optArg )
	
end

--------------------------------------------------------------------------------

return KSJsonEncoder
