diff Core/RestApi/RestApiOutput.cpp @ 1046:00f9f36bcd94

on-the-fly conversion of JSON to XML according to HTTP Accept
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Jul 2014 17:15:34 +0200
parents 8d1845feb277
children 648bf1457113
line wrap: on
line diff
--- a/Core/RestApi/RestApiOutput.cpp	Fri Jul 18 16:41:10 2014 +0200
+++ b/Core/RestApi/RestApiOutput.cpp	Fri Jul 18 17:15:34 2014 +0200
@@ -40,7 +40,8 @@
 namespace Orthanc
 {
   RestApiOutput::RestApiOutput(HttpOutput& output) : 
-    output_(output)
+    output_(output),
+    convertJsonToXml_(false)
   {
     alreadySent_ = false;
   }
@@ -71,9 +72,25 @@
   void RestApiOutput::AnswerJson(const Json::Value& value)
   {
     CheckStatus();
-    Json::StyledWriter writer;
-    std::string s = writer.write(value);
-    output_.AnswerBufferWithContentType(s, "application/json");
+
+    if (convertJsonToXml_)
+    {
+#if ORTHANC_PUGIXML_ENABLED == 1
+      std::string s;
+      Toolbox::JsonToXml(s, value);
+      output_.AnswerBufferWithContentType(s, "application/xml");
+#else
+      LOG(ERROR) << "Orthanc was compiled without XML support";
+      throw OrthancException(ErrorCode_InternalError);
+#endif
+    }
+    else
+    {
+      Json::StyledWriter writer;
+      std::string s = writer.write(value);
+      output_.AnswerBufferWithContentType(s, "application/json");
+    }
+
     alreadySent_ = true;
   }