Make propertyValueFormatError more typesafe

Similar to other patches, make propertyValueFormatError accept a
nlohmann::json object, which removes a lot of the unsafe dump code that
we have littered about.

Tested: No easy to replicate error.  Code is identical to previous
patchsets.  Inspection and code compilation only.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic9d0f196b6e198073189f744b738db7ffa2f1b74
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 77aa895..a396603 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -248,10 +248,10 @@
  * @param[in] arg2 Parameter of message that will replace %2 in its body.
  *
  * @returns Message PropertyValueFormatError formatted to JSON */
-nlohmann::json propertyValueFormatError(std::string_view arg1,
+nlohmann::json propertyValueFormatError(const nlohmann::json& arg1,
                                         std::string_view arg2);
 
-void propertyValueFormatError(crow::Response& res, std::string_view arg1,
+void propertyValueFormatError(crow::Response& res, const nlohmann::json& arg1,
                               std::string_view arg2);
 
 /**
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 411659d..9aadaea 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -1261,11 +1261,8 @@
                                      address, "SubnetMask", subnetMask,
                                      "Gateway", gateway))
             {
-                messages::propertyValueFormatError(
-                    asyncResp->res,
-                    thisJson.dump(2, ' ', true,
-                                  nlohmann::json::error_handler_t::replace),
-                    pathString);
+                messages::propertyValueFormatError(asyncResp->res, thisJson,
+                                                   pathString);
                 return;
             }
 
@@ -1386,11 +1383,8 @@
                     messages::resourceCannotBeDeleted(asyncResp->res);
                     return;
                 }
-                messages::propertyValueFormatError(
-                    asyncResp->res,
-                    thisJson.dump(2, ' ', true,
-                                  nlohmann::json::error_handler_t::replace),
-                    pathString);
+                messages::propertyValueFormatError(asyncResp->res, thisJson,
+                                                   pathString);
                 return;
             }
 
@@ -1455,11 +1449,8 @@
             if (!json_util::readJson(thisJsonCopy, asyncResp->res, "Address",
                                      address, "PrefixLength", prefixLength))
             {
-                messages::propertyValueFormatError(
-                    asyncResp->res,
-                    thisJson.dump(2, ' ', true,
-                                  nlohmann::json::error_handler_t::replace),
-                    pathString);
+                messages::propertyValueFormatError(asyncResp->res, thisJson,
+                                                   pathString);
                 return;
             }
 
@@ -1526,11 +1517,8 @@
                     messages::resourceCannotBeDeleted(asyncResp->res);
                     return;
                 }
-                messages::propertyValueFormatError(
-                    asyncResp->res,
-                    thisJson.dump(2, ' ', true,
-                                  nlohmann::json::error_handler_t::replace),
-                    pathString);
+                messages::propertyValueFormatError(asyncResp->res, thisJson,
+                                                   pathString);
                 return;
             }
 
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 02bb21f..28a7ac6 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -375,7 +375,7 @@
                     if (value == nullptr)
                     {
                         messages::propertyValueFormatError(
-                            asyncResp->res, item.value().dump(2, 1),
+                            asyncResp->res, item.value(),
                             "HttpHeaders/" + item.key());
                         return;
                     }
@@ -614,7 +614,7 @@
                     if (value == nullptr)
                     {
                         messages::propertyValueFormatError(
-                            asyncResp->res, it.value().dump(2, ' ', true),
+                            asyncResp->res, it.value(),
                             "HttpHeaders/" + it.key());
                         return;
                     }
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 5a7105f..52aeb43 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -588,11 +588,8 @@
                                  address, "SubnetMask", subnetMask, "Gateway",
                                  gateway))
         {
-            messages::propertyValueFormatError(
-                asyncResp->res,
-                thisJson.dump(2, ' ', true,
-                              nlohmann::json::error_handler_t::replace),
-                pathString);
+            messages::propertyValueFormatError(asyncResp->res, thisJson,
+                                               pathString);
             return;
         }
 
@@ -893,11 +890,8 @@
             // One and only one hypervisor instance supported
             if (ipv4Static.size() != 1)
             {
-                messages::propertyValueFormatError(
-                    asyncResp->res,
-                    ipv4Static.dump(2, ' ', true,
-                                    nlohmann::json::error_handler_t::replace),
-                    "IPv4StaticAddresses");
+                messages::propertyValueFormatError(asyncResp->res, ipv4Static,
+                                                   "IPv4StaticAddresses");
                 return;
             }
 
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 362fdef..5bb4908 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -707,7 +707,7 @@
     if (config.empty())
     {
         BMCWEB_LOG_ERROR << "Empty Zones";
-        messages::propertyValueFormatError(response->res, "[]", "Zones");
+        messages::propertyValueFormatError(response->res, config, "Zones");
         return false;
     }
     for (auto& odata : config)
@@ -727,8 +727,7 @@
         {
             BMCWEB_LOG_ERROR << "Got invalid path " << path;
             BMCWEB_LOG_ERROR << "Illegal Type Zones";
-            messages::propertyValueFormatError(response->res, odata.dump(),
-                                               "Zones");
+            messages::propertyValueFormatError(response->res, odata, "Zones");
             return false;
         }
         std::replace(input.begin(), input.end(), '_', ' ');
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index abc817d..64b5abb 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -478,14 +478,16 @@
  * See header file for more information
  * @endinternal
  */
-nlohmann::json propertyValueFormatError(std::string_view arg1,
+nlohmann::json propertyValueFormatError(const nlohmann::json& arg1,
                                         std::string_view arg2)
 {
+    std::string arg1Str = arg1.dump(2, ' ', true,
+                                    nlohmann::json::error_handler_t::replace);
     return getLog(redfish::registries::base::Index::propertyValueFormatError,
-                  std::to_array({arg1, arg2}));
+                  std::to_array<std::string_view>({arg1Str, arg2}));
 }
 
-void propertyValueFormatError(crow::Response& res, std::string_view arg1,
+void propertyValueFormatError(crow::Response& res, const nlohmann::json& arg1,
                               std::string_view arg2)
 {
     res.result(boost::beast::http::status::bad_request);