From c14c6ad29e01143d2951769cf22093763ff1a4fd Mon Sep 17 00:00:00 2001 From: Abbas536952 Date: Fri, 7 May 2021 15:42:32 +0500 Subject: [PATCH] fixed bug of json serialize when creating engagement --- .../Api/Engagement/Dto/EngagementHubSpotModel.cs | 2 +- HubSpot.NET/Core/HubSpotBaseClient.cs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/HubSpot.NET/Api/Engagement/Dto/EngagementHubSpotModel.cs b/HubSpot.NET/Api/Engagement/Dto/EngagementHubSpotModel.cs index d58cf230..fc44a468 100644 --- a/HubSpot.NET/Api/Engagement/Dto/EngagementHubSpotModel.cs +++ b/HubSpot.NET/Api/Engagement/Dto/EngagementHubSpotModel.cs @@ -49,7 +49,7 @@ public class EngagementHubSpotAssociationsModel public class EngagementHubSpotEngagementModel { [DataMember(Name = "id")] - public long? Id { get; set; } + public long Id { get; set; } [DataMember(Name = "type")] public string Type { get;set; } diff --git a/HubSpot.NET/Core/HubSpotBaseClient.cs b/HubSpot.NET/Core/HubSpotBaseClient.cs index 2084b4b3..3aa6a2ca 100644 --- a/HubSpot.NET/Core/HubSpotBaseClient.cs +++ b/HubSpot.NET/Core/HubSpotBaseClient.cs @@ -4,6 +4,7 @@ namespace HubSpot.NET.Core using HubSpot.NET.Core.Interfaces; using HubSpot.NET.Core.Serializers; using Newtonsoft.Json; + using Newtonsoft.Json.Serialization; using RestSharp; using System.Collections.Generic; @@ -110,9 +111,15 @@ public void UpdateToken(HubSpotToken token) private T SendReceiveRequest(string path, Method method, K entity) where T: new() { RestRequest request = ConfigureRequestAuthentication(path, method); - - if(!entity.Equals(default(K))) - request.AddJsonBody(entity); + + var json = JsonConvert.SerializeObject(entity, new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }); + + if (!entity.Equals(default(K))) + request.AddJsonBody(json); IRestResponse response = _client.Execute(request); @@ -179,7 +186,6 @@ private RestRequest ConfigureRequestAuthentication(string path, Method method) break; } - request.JsonSerializer = new NewtonsoftRestSharpSerializer(); return request; }