changeset 3314:7eb5405b7ed8

Enlarge the support of JSON-to-XML conversion in the REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 Feb 2019 09:29:48 +0100
parents 3e0ad879eba2
children 8bf33fa68435
files Core/RestApi/RestApiOutput.cpp NEWS
diffstat 2 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Core/RestApi/RestApiOutput.cpp	Wed Feb 27 08:14:40 2019 +0100
+++ b/Core/RestApi/RestApiOutput.cpp	Thu Feb 28 09:29:48 2019 +0100
@@ -128,9 +128,29 @@
                                    MimeType contentType)
   {
     CheckStatus();
-    output_.SetContentType(contentType);
-    output_.Answer(buffer, length);
-    alreadySent_ = true;
+
+    if (convertJsonToXml_ &&
+        contentType == MimeType_Json)
+    {
+      Json::Value json;
+      Json::Reader reader;
+      if (reader.parse(reinterpret_cast<const char*>(buffer),
+                       reinterpret_cast<const char*>(buffer) + length, json))
+      {
+        AnswerJson(json);
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_BadFileFormat,
+                               "The REST API tries and answers with an invalid JSON file");
+      } 
+    }
+    else
+    {
+      output_.SetContentType(contentType);
+      output_.Answer(buffer, length);
+      alreadySent_ = true;
+    }
   }
 
   void RestApiOutput::Redirect(const std::string& path)
--- a/NEWS	Wed Feb 27 08:14:40 2019 +0100
+++ b/NEWS	Thu Feb 28 09:29:48 2019 +0100
@@ -1,12 +1,19 @@
 Pending changes in the mainline
 ===============================
 
-General
--------
-* Orthanc Explorer : when performing a Query/Retrieve operation, the tag
-  default values are now set to an empty string instead of '*', which allows
-  to match even if the tag is not present. This allows malformed DICOM files
-  to be matched, even though they lack required tags such as `PatientSex`
+Orthanc Explorer
+----------------
+
+* If performing a Query/Retrieve operation, the default value for the
+  tags is set to an empty string instead of '*', which allows to match
+  even if the tag is not present. This allows malformed DICOM files to
+  be matched, even though they lack required tags such as "PatientSex"
+
+Maintenance
+-----------
+
+* Enlarge the support of JSON-to-XML conversion in the REST API
+
 
 Version 1.5.5 (2019-02-25)
 ==========================