private static void SerializeConfiguration(JsonTextWriter writer, HystrixConfiguration config)
        {

            writer.WriteStartObject();
            writer.WriteStringField("type", "HystrixConfig");
            writer.WriteObjectFieldStart("commands");
            foreach (var entry in config.CommandConfig)
            {
                IHystrixCommandKey key = entry.Key;
                HystrixCommandConfiguration commandConfig = entry.Value;
                WriteCommandConfigJson(writer, key, commandConfig);

            }
            writer.WriteEndObject();

            writer.WriteObjectFieldStart("threadpools");
            foreach (var entry in config.ThreadPoolConfig)
            {
                IHystrixThreadPoolKey threadPoolKey = entry.Key;
                HystrixThreadPoolConfiguration threadPoolConfig = entry.Value;
                WriteThreadPoolConfigJson(writer, threadPoolKey, threadPoolConfig);
            }
            writer.WriteEndObject();

            writer.WriteObjectFieldStart("collapsers");
            foreach (var entry in config.CollapserConfig)
            {
                IHystrixCollapserKey collapserKey = entry.Key;
                HystrixCollapserConfiguration collapserConfig = entry.Value;
                WriteCollapserConfigJson(writer, collapserKey, collapserConfig);
            }
            writer.WriteEndObject();
            writer.WriteEndObject();

        }
 private static void WriteCommandConfigJson(JsonTextWriter json, IHystrixCommandKey key, HystrixCommandConfiguration commandConfig)
 {
     json.WriteObjectFieldStart(key.Name);
     json.WriteStringField("threadPoolKey", commandConfig.ThreadPoolKey.Name);
     json.WriteStringField("groupKey", commandConfig.GroupKey.Name);
     json.WriteObjectFieldStart("execution");
     HystrixCommandConfiguration.HystrixCommandExecutionConfig executionConfig = commandConfig.ExecutionConfig;
     json.WriteStringField("isolationStrategy", executionConfig.IsolationStrategy.ToString());
     json.WriteStringField("threadPoolKeyOverride", executionConfig.ThreadPoolKeyOverride);
     json.WriteBooleanField("requestCacheEnabled", executionConfig.IsRequestCacheEnabled);
     json.WriteBooleanField("requestLogEnabled", executionConfig.IsRequestLogEnabled);
     json.WriteBooleanField("timeoutEnabled", executionConfig.IsTimeoutEnabled);
     json.WriteBooleanField("fallbackEnabled", executionConfig.IsFallbackEnabled);
     json.WriteIntegerField("timeoutInMilliseconds", executionConfig.TimeoutInMilliseconds);
     json.WriteIntegerField("semaphoreSize", executionConfig.SemaphoreMaxConcurrentRequests);
     json.WriteIntegerField("fallbackSemaphoreSize", executionConfig.FallbackMaxConcurrentRequest);
     json.WriteBooleanField("threadInterruptOnTimeout", executionConfig.IsThreadInterruptOnTimeout);
     json.WriteEndObject();
     json.WriteObjectFieldStart("metrics");
     HystrixCommandConfiguration.HystrixCommandMetricsConfig metricsConfig = commandConfig.MetricsConfig;
     json.WriteIntegerField("healthBucketSizeInMs", metricsConfig.HealthIntervalInMilliseconds);
     json.WriteIntegerField("percentileBucketSizeInMilliseconds", metricsConfig.RollingPercentileBucketSizeInMilliseconds);
     json.WriteIntegerField("percentileBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteBooleanField("percentileEnabled", metricsConfig.IsRollingPercentileEnabled);
     json.WriteIntegerField("counterBucketSizeInMilliseconds", metricsConfig.RollingCounterBucketSizeInMilliseconds);
     json.WriteIntegerField("counterBucketCount", metricsConfig.RollingCounterNumberOfBuckets);
     json.WriteEndObject();
     json.WriteObjectFieldStart("circuitBreaker");
     HystrixCommandConfiguration.HystrixCommandCircuitBreakerConfig circuitBreakerConfig = commandConfig.CircuitBreakerConfig;
     json.WriteBooleanField("enabled", circuitBreakerConfig.IsEnabled);
     json.WriteBooleanField("isForcedOpen", circuitBreakerConfig.IsForceOpen);
     json.WriteBooleanField("isForcedClosed", circuitBreakerConfig.IsForceOpen);
     json.WriteIntegerField("requestVolumeThreshold", circuitBreakerConfig.RequestVolumeThreshold);
     json.WriteIntegerField("errorPercentageThreshold", circuitBreakerConfig.ErrorThresholdPercentage);
     json.WriteIntegerField("sleepInMilliseconds", circuitBreakerConfig.SleepWindowInMilliseconds);
     json.WriteEndObject();
     json.WriteEndObject();
 }