diff --git a/AUTHORS.txt b/AUTHORS.txt index ff04386..3a274e0 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -1 +1,2 @@ -Renato Golia \ No newline at end of file +Renato Golia +Elin Danielsson diff --git a/src/MassTransit/Configuration/IServiceBusFactory.cs b/src/MassTransit/Configuration/IServiceBusFactory.cs index cdd4f1b..1b9f931 100644 --- a/src/MassTransit/Configuration/IServiceBusFactory.cs +++ b/src/MassTransit/Configuration/IServiceBusFactory.cs @@ -1,7 +1,11 @@ using System; using System.Collections.Generic; +using System.Globalization; +using System.Linq; using MassTransit; using MassTransit.SubscriptionConfigurators; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Nybus.MassTransit; namespace Nybus.Configuration @@ -41,6 +45,10 @@ public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDe bus.ReceiveFrom(receiveUri); bus.UseJsonSerializer(); + + bus.ConfigureJsonSerializer(ConfigureIsoDateTimeConverters); + bus.ConfigureJsonDeserializer(ConfigureIsoDateTimeConverters); + bus.SetConcurrentConsumerLimit(_concurrencyLimit); foreach (var subscription in subscriptions) @@ -49,6 +57,18 @@ public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDe bus.Validate(); }); } + + private static JsonSerializerSettings ConfigureIsoDateTimeConverters(JsonSerializerSettings settings) + { + var isoDateTimeConverters = settings.Converters.OfType().ToArray(); + + foreach (var converter in isoDateTimeConverters) + { + converter.Culture = CultureInfo.InvariantCulture; + } + + return settings; + } } public class LoopbackServiceBusFactory : IServiceBusFactory @@ -64,6 +84,9 @@ public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDe bus.ReceiveFrom(receiveUri); bus.UseJsonSerializer(); + bus.ConfigureJsonSerializer(ConfigureIsoDateTimeConverters); + bus.ConfigureJsonDeserializer(ConfigureIsoDateTimeConverters); + foreach (var subscription in subscriptions) bus.Subscribe(subscription); @@ -71,5 +94,17 @@ public IServiceBus CreateServiceBus(MassTransitConnectionDescriptor connectionDe }); } + + private static JsonSerializerSettings ConfigureIsoDateTimeConverters(JsonSerializerSettings settings) + { + var isoDateTimeConverters = settings.Converters.OfType().ToArray(); + + foreach (var converter in isoDateTimeConverters) + { + converter.Culture = CultureInfo.InvariantCulture; + } + + return settings; + } } } \ No newline at end of file