Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize Customization and usage #104

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading