Skip to content

Commit

Permalink
Serialize Customization and usage (#104)
Browse files Browse the repository at this point in the history
* Log changes

* Serialization settings and examples to use it

---------

Co-authored-by: Katari.Manikanta <[email protected]>
  • Loading branch information
Mkatari3700 and Katari.Manikanta authored Feb 13, 2024
1 parent 00a4bec commit 0278918
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Conductor/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Conductor.Client
/// </summary>
public partial class ApiClient
{
private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
public JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
Expand Down Expand Up @@ -341,7 +341,7 @@ public String Serialize(object obj)
{
try
{
return obj != null ? JsonConvert.SerializeObject(obj) : null;
return obj != null ? JsonConvert.SerializeObject(obj, serializerSettings) : null;
}
catch (Exception e)
{
Expand Down
16 changes: 15 additions & 1 deletion Conductor/Client/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.IO;
using System;
using RestSharp;
using System.Net.Http;
using Newtonsoft.Json;

namespace Conductor.Client
{
Expand Down Expand Up @@ -93,6 +93,20 @@ public Configuration(int? timeOut = null)
DefaultHeader = new ConcurrentDictionary<string, string>();
}

/// <summary>
/// Initializes a new instance of the <see cref="Configuration" /> class
/// </summary>
/// <param name="serializerSettings">JsonSerializerSettings setting custom serialization properties</param>
/// <param name="timeOut">Optional rest client request time out</param>
public Configuration(JsonSerializerSettings serializerSettings, int? timeOut = null)
{
Timeout = timeOut ?? Timeout;
ApiClient = new ApiClient(Timeout);
ApiClient.serializerSettings = serializerSettings;
BasePath = "https://play.orkes.io/api";
DefaultHeader = new ConcurrentDictionary<string, string>();
}

#endregion Constructors

#region Properties
Expand Down
31 changes: 29 additions & 2 deletions csharp-examples/WorkFlowExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Conductor.Executor;
using Conductor.Api;
using Conductor.Client.Authentication;
using Conductor.Client.Extensions;
using Newtonsoft.Json;

namespace csharp_examples
{
Expand All @@ -30,12 +30,39 @@ public class WorkFlowExamples

public void RegisterWorkFlow()
{
Configuration configuration = new Configuration(REST_CLIENT_REQUEST_TIME_OUT)
// Method-1 for using custom serialization settings - START

// Step 1:- Prepare JsonSerializer Settings with certain properties
JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};

// Step 2:- Use overloaded constructor of Configuration and pass the JsonSerializer Settings
// Restclient internally use the settings to serialize on request/response while making a call to serialize/deserialize
Configuration configuration = new Configuration(jsonSerializerSettings, REST_CLIENT_REQUEST_TIME_OUT)
{
AuthenticationSettings = new OrkesAuthenticationSettings(KEY_ID, KEY_SECRET)
};

WorkflowExecutor executor = new WorkflowExecutor(configuration);
executor.RegisterWorkflow(GetConductorWorkflow(), true);
// Method-1 for using custom serialization settings - END


// Method-2 for using custom serialization settings - START
/*
Configuration configuration = new Configuration();
configuration.ApiClient.serializerSettings = new JsonSerializerSettings()
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
WorkflowExecutor executor = new WorkflowExecutor(configuration);
executor.RegisterWorkflow(GetConductorWorkflow(), true);
*/
// Method-2 for using custom serialization settings - END
}

private ConductorWorkflow GetConductorWorkflow()
Expand Down

0 comments on commit 0278918

Please sign in to comment.