Hello,
I am getting error when deserializing BulkResponse returned by a REST call on the client side.
"Additional text found in JSON string after finishing deserializing object."
Client and Service are quite straight forward currently.
public class ElasticSearchIndexerClient : BaseClient
{
public BulkResponse AddDocuments(Guid indexName, List<ESDocument> esDocumentList)
{
var response = Post(esDocumentList, routePrefix + "addDocuments/" + indexName.ToString());
BulkResponse resp = GetResponse<BulkResponse>(response);
return resp;
}
public static T GetResponse<T>(HttpResponseMessage httpResponse) where T : IResponse
{
try
{
var content = httpResponse.Content.ReadAsStringAsync().Result;
**T response = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(content);**
return response;
}
catch (Exception)
{
return default(T);
}
}
}
I have a rest service to control writes to ElasticSearch as shown below:
[RoutePrefix("api/indexer")]
public class IndexerController : ApiController
{
public ElasticSearchRepositoryWriter ESRepoWriter { get; private set; }
[Route("addDocuments/{indexName}"), HttpPost]
public Nest.BulkResponse AddDocuments(Guid indexName, [FromBody]List<ESDocument> esDocumentList)
{
ESRepoWriter.SetIndex(indexName);
var response = ESRepoWriter.AddDocumentss(esDocumentList);
return response as BulkResponse;
}
}
Service uses JsonFormatter, so both sides are using Newtonsoft.Json. In debug mode, I can see that the returned json content is correct.
Please advise how to resolve the issue. Is it not ok to return Nest.BulkResponse and other Nest objects?
Thanks in advance.
Regards,
Raj