Mercurial > hg > orthanc
diff Core/RestApi/RestApiOutput.cpp @ 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 | 4e43e67f8ecf |
children | 94f4a18a79cc |
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)