c# - Marketo - Response of Bulk API serialization
问题描述
I'm trying to use the Bulk Import API endpoint within Marketo to fetch the warnings and failures associated with a bulk job I created within Marketo.
The output of these jobs is stated as an ObservableOfInputStreamContent
, yet the response of these endpoints returns a csv string (with header column), that's not a JSON object. To compound to this problem, we are using the generated swagger files with the swagger definition file provided by Marketo. These generated c# client side files have the ObservableOfInputStreamContent
object, but it's an empty object. I'm not sure if this is intended, or a mistake on Marketo's side. The generated files will attempt to use Newtonsoft.Json.JsonConvert.DeserializeObject<ObservableOfInputStreamContent>(responseText, JsonSerializerSettings);
to deserialize the API response to the ObservableOfInputStreamContent
.
Generated code that deserializes the API response:
var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(responseText, JsonSerializerSettings);
return new ObjectResponseResult<T>(typedBody, responseText);
}
catch (Newtonsoft.Json.JsonException exception)
{
var message = "Could not deserialize the response body string as " + typeof(T).FullName + ".";
throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
}
Problem one is that the API does not return JSON to begin with (eg):
address,city,country,
123 lane, new york, USA
745 street, new york, USA
This call will return this error because of this:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: a. Path '', line 0, position 0.
The second issue is that ObservableOfInputStreamContent
is defined as an empty object to begin with in the generated files. So if the API response was valid JSON, I don't think it would know how to convert to that empty ObservableOfInputStreamContent
object. The good news about the generated code is that it gives me an option to extend the ObservableOfInputStreamContent
because it's defined as a partial
class.
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.11.0 (Newtonsoft.Json v11.0.0.0)")]
public partial class ObservableOfInputStreamContent
{
}
That said, is there any possible way I can use the JsonSerializerSettings
to get around this issue? Could I extended the ObservableOfInputStreamContent
class to hold a string property and then create my own JsonConverter to convert the string returned from the API into the new ObservableOfInputStreamContent
?
解决方案
推荐阅读
- postgresql - sql更新表条件取决于同一张表中的其他行
- javascript - 反应本机导航错误-TypeError:无法读取未定义的属性'catch'
- android - MockK - 左匹配器的匹配模拟签名失败:[any(), any()]
- regex - 如何使用可选的无序查询字符串重定向 URL 并将其保存在 Nginx 中
- vue.js - 动作中的 Vuex 访问状态很奇怪
- python - 每次更新我的条目时如何调用函数
- javascript - 在 flatpickr 中允许日期小于 minDate
- reactjs - 从 mapstatetoprops 重构为 React 中的钩子
- capacitor - 在离子电容器 LocalNotification 中每天但在不同时间重复相同通知的最佳方式
- node.js - 构建 docker 映像时,npm install 在 skaffold 中失败