Mercurial > hg > orthanc
comparison 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 |
comparison
equal
deleted
inserted
replaced
3313:3e0ad879eba2 | 3314:7eb5405b7ed8 |
---|---|
126 void RestApiOutput::AnswerBuffer(const void* buffer, | 126 void RestApiOutput::AnswerBuffer(const void* buffer, |
127 size_t length, | 127 size_t length, |
128 MimeType contentType) | 128 MimeType contentType) |
129 { | 129 { |
130 CheckStatus(); | 130 CheckStatus(); |
131 output_.SetContentType(contentType); | 131 |
132 output_.Answer(buffer, length); | 132 if (convertJsonToXml_ && |
133 alreadySent_ = true; | 133 contentType == MimeType_Json) |
134 { | |
135 Json::Value json; | |
136 Json::Reader reader; | |
137 if (reader.parse(reinterpret_cast<const char*>(buffer), | |
138 reinterpret_cast<const char*>(buffer) + length, json)) | |
139 { | |
140 AnswerJson(json); | |
141 } | |
142 else | |
143 { | |
144 throw OrthancException(ErrorCode_BadFileFormat, | |
145 "The REST API tries and answers with an invalid JSON file"); | |
146 } | |
147 } | |
148 else | |
149 { | |
150 output_.SetContentType(contentType); | |
151 output_.Answer(buffer, length); | |
152 alreadySent_ = true; | |
153 } | |
134 } | 154 } |
135 | 155 |
136 void RestApiOutput::Redirect(const std::string& path) | 156 void RestApiOutput::Redirect(const std::string& path) |
137 { | 157 { |
138 CheckStatus(); | 158 CheckStatus(); |