Skip to content

Commit

Permalink
Fix CreateInternalSettings to properly wire everything up and be hard…
Browse files Browse the repository at this point in the history
…er to goof up later by making static, fix hocon reading
  • Loading branch information
to11mtm committed Apr 10, 2021
1 parent 0d5b076 commit 7c72de5
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/core/Akka/Serialization/NewtonSoftJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type> GetConverterTypes(Config config)
Expand Down Expand Up @@ -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
{
Expand All @@ -212,14 +217,14 @@ private JsonSerializerSettings createInternalSettings(
.Get<NewtonSoftJsonSerializerSetup>()
.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)
Expand All @@ -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;
}

Expand Down

0 comments on commit 7c72de5

Please sign in to comment.