web::json::value odata_json_writer_minimal::serialize(std::shared_ptr<odata_value> value_object)
{
	::utility::stringstream_t ss;

	if (value_object)
	{
		handle_serialize_odata_value(ss, value_object->get_value_type(), value_object);
	}

	return web::json::value::parse(ss);
}
void odata_json_operation_payload_parameter_writer::handle_serialize_odata_properties(::utility::stringstream_t& ss, const odata_property_map& properties)
{
	if (properties.size() <= 0)
	{
		ss << "null";

		return ;
	}

	ss << U("{");

	bool first = true;

	for (auto iter = properties.cbegin(); iter != properties.cend(); iter++)
	{	
		if (!iter->second)
		{
			if (!first)
			{
				ss << U(",");
			}

			ss << U('"') << iter->first << U('"') << U(":") << U("null");

			first = false;
		}
		else
		{
			auto property_type = iter->second->get_value_type();

			if (!is_type_serializable(property_type))
			{
				continue;
			}

			if (!first)
			{
				ss << U(",");
			}

			ss << U('"') << iter->first << U('"') << U(":");

			handle_serialize_odata_value(ss, property_type, iter->second);

			first = false;
		}
		
	}

	ss << U("}");
}
void odata_json_operation_payload_parameter_writer::handle_serialize_odata_parameter(
	::utility::stringstream_t& ss, const std::shared_ptr<::odata::core::odata_parameter>& parameter, ::utility::char_t mark, ::utility::char_t separator)
{
	if (parameter && parameter->get_value() && !parameter->get_name().empty())
	{
		if (mark)
		{
			ss << mark << parameter->get_name() << mark;
		}
		else
		{
			ss << parameter->get_name();
		}

		ss << separator;

		handle_serialize_odata_value(ss, parameter->get_value()->get_value_type(), parameter->get_value());
	}
}
void odata_json_operation_payload_parameter_writer::handle_serialize_collection_value(::utility::stringstream_t& ss, const std::shared_ptr<odata_collection_value>& p_value)
{
	if (!p_value)
	{
		return ;
	}

	if (p_value->get_collection_values().size() == 0)
	{
		ss << U("[]");

		return ;
	}

	ss << U("[");

	bool first = true;

	auto element_type = p_value->get_collection_values()[0]->get_value_type();

	for (auto iter = p_value->get_collection_values().cbegin(); iter != p_value->get_collection_values().cend(); iter++)
	{
		if (!is_type_serializable(element_type))
		{
			continue;
		}

		if (!first)
		{
			ss << U(",");
		}

		handle_serialize_odata_value(ss, element_type, *iter);

		first = false;
	}

	ss << U("]");
}