diff OrthancServer/Plugins/Engine/OrthancPlugins.cpp @ 4392:3af1d763763a

confining Json::Reader and Json::*Writer into Toolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Dec 2020 18:09:47 +0100
parents 79ef2b6d8e76
children f7104e9d044c
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Dec 21 08:47:29 2020 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Dec 21 18:09:47 2020 +0100
@@ -2670,18 +2670,17 @@
       case _OrthancPluginService_GetInstanceJson:
       case _OrthancPluginService_GetInstanceSimplifiedJson:
       {
-        Json::StyledWriter writer;
         std::string s;
 
         if (service == _OrthancPluginService_GetInstanceJson)
         {
-          s = writer.write(instance.GetJson());
+          Toolbox::WriteJson(s, instance.GetJson(), false /* styled writer */);
         }
         else
         {
           Json::Value simplified;
           Toolbox::SimplifyDicomAsJson(simplified, instance.GetJson(), DicomToJsonFormat_Human);
-          s = writer.write(simplified);
+          Toolbox::WriteJson(s, simplified, false /* styled writer */);
         }
 
         *p.resultStringToFree = CopyString(s);
@@ -2882,8 +2881,9 @@
           json, Plugins::Convert(p.format), 
           static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength);
 
-        Json::FastWriter writer;
-        *p.targetStringToFree = CopyString(writer.write(json));        
+        std::string s;
+        Toolbox::WriteJson(s, json, true /* fast */);
+        *p.targetStringToFree = CopyString(s);        
         return;
       }
       
@@ -3379,8 +3379,9 @@
     dicom->DatasetToJson(json, Plugins::Convert(p.format), 
                          static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength);
 
-    Json::FastWriter writer;
-    *p.result = CopyString(writer.write(json));
+    std::string s;
+    Toolbox::WriteJson(s, json, true /* fast */);
+    *p.result = CopyString(s);
   }
         
 
@@ -3396,13 +3397,9 @@
     {
       json = Json::objectValue;
     }
-    else
-    {
-      Json::Reader reader;
-      if (!reader.parse(p.json, json))
-      {
-        throw OrthancException(ErrorCode_BadJson);
-      }
+    else if (!Toolbox::ReadJson(json, p.json))
+    {
+      throw OrthancException(ErrorCode_BadJson);
     }
 
     std::string dicom;