diff --git a/src/core/Akka/Serialization/NewtonSoftJsonSerializer.cs b/src/core/Akka/Serialization/NewtonSoftJsonSerializer.cs index edd247ed3cc..f78a5a20aac 100644 --- a/src/core/Akka/Serialization/NewtonSoftJsonSerializer.cs +++ b/src/core/Akka/Serialization/NewtonSoftJsonSerializer.cs @@ -57,12 +57,17 @@ public static NewtonSoftJsonSerializerSettings Create(Config config) return new NewtonSoftJsonSerializerSettings( encodeTypeNames: config.GetBoolean("encode-type-names", true), - preserveObjectReferences: config.GetBoolean("preserve-object-references", true), + preserveObjectReferences: config.GetBoolean( + "preserve-object-references", true), converters: GetConverterTypes(config), - config.GetBoolean("use-pooled-string-builder",true), - config.GetInt("pooled-string-builder-minsize",2048), - config.GetInt("pooled-string-builder-maxsize", 32768) - ); + config.GetBoolean("use-pooled-string-builder", true), + (int)Math.Min( + config.GetByteSize("pooled-string-builder-minsize", 2048) ?? + 2048, int.MaxValue), + (int)Math.Min( + config.GetByteSize("pooled-string-builder-maxsize", + 32768) ?? 32768, int.MaxValue) + ); } private static IEnumerable GetConverterTypes(Config config) @@ -181,15 +186,15 @@ public NewtonSoftJsonSerializer(ExtendedActorSystem system, NewtonSoftJsonSerial settings.StringBuilderMaxSize }); } - Settings = createInternalSettings(system, settings); - var settingsNoFormat = createInternalSettings(system, settings); + Settings = CreateInternalSettings(system, settings,this); + var settingsNoFormat = CreateInternalSettings(system, settings,this); settingsNoFormat.Formatting = Formatting.None; _serializer = JsonSerializer.Create(Settings); _formattingNoneSerializer = JsonSerializer.Create(settingsNoFormat); } - private JsonSerializerSettings createInternalSettings( - ExtendedActorSystem system, NewtonSoftJsonSerializerSettings settings) + private static JsonSerializerSettings CreateInternalSettings( + ExtendedActorSystem system, NewtonSoftJsonSerializerSettings settings, NewtonSoftJsonSerializer surrogateParent) { var newSettings = new JsonSerializerSettings { @@ -212,14 +217,14 @@ private JsonSerializerSettings createInternalSettings( .Get() .GetOrElse(NewtonSoftJsonSerializerSetup.Create(s => { })); - settingsSetup.ApplySettings(Settings); + settingsSetup.ApplySettings(newSettings); } var converters = settings.Converters .Select(type => CreateConverter(type, system)) .ToList(); - converters.Add(new SurrogateConverter(this)); + converters.Add(new SurrogateConverter(surrogateParent)); converters.Add(new DiscriminatedUnionConverter()); foreach (var converter in converters) @@ -231,10 +236,6 @@ private JsonSerializerSettings createInternalSettings( ObjectCreationHandling .Replace; //important: if reuse, the serializer will overwrite properties in default references, e.g. Props.DefaultDeploy or Props.noArgs newSettings.ContractResolver = new AkkaContractResolver(); - if (settings.UsePooledStringBuilder) - { - - } return newSettings; }