-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Customizable serializers #2514
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
Customizable serializers #2514
Conversation
Some background here, and I've verified this with your current codebase too. By exposing the |
3e39d19
to
a06434f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the idea and the implementation thus far, but needs some spec coverage, additional HOCON settings for JSON.NET, and some XML-DOC comments on any public members.
} | ||
} | ||
|
||
public sealed class HyperionSerializerSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs XML-DOC comments per @sean-gilliam's initiative
@@ -19,6 +21,39 @@ | |||
|
|||
namespace Akka.Serialization | |||
{ | |||
internal sealed class NewtonSoftJsonSerializerSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again with the XML-DOC comments. Should also be made public
since this file is going to be moved out of Akka.NET core in the near future
_serializer = JsonSerializer.Create(_settings); | ||
} | ||
|
||
public NewtonSoftJsonSerializer(ExtendedActorSystem system, Config config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XML-DOC
{ | ||
if (config == null) throw new ArgumentNullException(nameof(config), "HyperionSerializerSettings require a config, default path: `akka.serializers.hyperion`"); | ||
|
||
var type = Type.GetType(config.GetString("known-types-provider"), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need some specs to verify that all of these settings can be loaded by the Hyperion serializer from a valid HOCON file.
hyperion { | ||
# If true, hyperion serializer will preserve references between objects. | ||
# This is necessary to support things such as cyclic dependencies between objects. | ||
preserve-object-references = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need specs to validate the defaults (protects against regressions where the defaults get changed by accident)
public NewtonSoftJsonSerializer(ExtendedActorSystem system, Config config) | ||
: base(system) | ||
{ | ||
var serializerSettings = NewtonSoftJsonSerializerSettings.Create(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need specs to validate that these settings can be correctly loaded from config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: what are the default JSON.NET HOCON settings? Shouldn't these be expressed somewhere also?
I've added config specs + 2 extra settings for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Resubmitted the perf test, but otherwise I think this is ready for merge. Lays the ground work for making serializers customizable and extensible in the future.
public class HyperionConfigTests | ||
{ | ||
[Fact] | ||
public void Hyperion_serializer_should_have_correct_defaults() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Horusiath. Looks great.
f230ff3
to
6721657
Compare
Motivation
Some of the users lack an ability to customize used serializers i.e. adding custom converters to json.net serializer. Another time some of them may want to harden serializer constraints on themselves in order to achieve better performance. This is especially a case with new Hyperion serializer, which uses things like preserving object references and version tolerance, which both increase the serialization time and a payload size, causing our default hyperion settings to be actually always a worst case scenario for that library.
Description
This PR introduces an ability to add custom options to serializers through HOCON config. It can be used as a general purpose mechanism. From now, users may define their own serializer configuration within
akka.actor.serialization-settings
i.e.:This way a
Config
object holding anakka.actor.serialization-settings.hyperion
section will be passed as a second parameter to constructor of a serializer aliased as "hyperion" inakka.actor.serializers
. From there, a serializer class is free to interpret it. This behavior is done atSerialization
class level, so it's applied automatically to any serializer, that wants to use it.This PR introduces this behavior on 2 serializers:
NewtonSoftJsonSerializer
may optionally take a config with a list of custom converter types to be added.HyperionSerializer
may optionally take a config with 3 settings:perserve-object-references
used to track references (not only values) in serialized object graph, including cyclic references.version-tolerance
which can be turned off to reduce a payload manifest size.known-types-provider
which takes a type name for a class implementingIKnownTypesProvider
- an interface that will be used at start of an actor system to provide a list of types, that are assumed to be known by all communicating sides using Hyperion serializer. This also can be used to optimize Hyperion usage.This new feature has its separate test to check if HOCON configs are bound to right serializers when serialization map is being created.