예제 #1
0
        public NewtonSoftJsonSerializer(ExtendedActorSystem system, NewtonSoftJsonSerializerSettings settings)
            : base(system)
        {
            var converters = settings.Converters
                             .Select(type => CreateConverter(type, system))
                             .ToList();

            converters.Add(new SurrogateConverter(this));
            converters.Add(new DiscriminatedUnionConverter());

            Settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = settings.PreserveObjectReferences
                    ? PreserveReferencesHandling.Objects
                    : PreserveReferencesHandling.None,
                Converters             = converters,
                NullValueHandling      = NullValueHandling.Ignore,
                DefaultValueHandling   = DefaultValueHandling.Ignore,
                MissingMemberHandling  = MissingMemberHandling.Ignore,
                ObjectCreationHandling = ObjectCreationHandling.Replace, //important: if reuse, the serializer will overwrite properties in default references, e.g. Props.DefaultDeploy or Props.noArgs
                ConstructorHandling    = ConstructorHandling.AllowNonPublicDefaultConstructor,
                TypeNameHandling       = settings.EncodeTypeNames
                    ? TypeNameHandling.All
                    : TypeNameHandling.None,
                ContractResolver = new AkkaContractResolver()
            };

            _serializer = JsonSerializer.Create(Settings);
        }
예제 #2
0
        public NewtonSoftJsonSerializer(ExtendedActorSystem system, NewtonSoftJsonSerializerSettings settings)
            : base(system)
        {
            if (settings.UsePooledStringBuilder)
            {
                _sbPool = new DefaultObjectPoolProvider()
                          .CreateStringBuilderPool(settings.StringBuilderMinSize, settings.StringBuilderMaxSize);
            }
            Settings = new JsonSerializerSettings
            {
                PreserveReferencesHandling = settings.PreserveObjectReferences
                    ? PreserveReferencesHandling.Objects
                    : PreserveReferencesHandling.None,
                NullValueHandling     = NullValueHandling.Ignore,
                DefaultValueHandling  = DefaultValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                ConstructorHandling   = ConstructorHandling.AllowNonPublicDefaultConstructor,
                TypeNameHandling      = settings.EncodeTypeNames
                    ? TypeNameHandling.All
                    : TypeNameHandling.None,
            };

            if (system != null)
            {
                var settingsSetup = system.Settings.Setup.Get <NewtonSoftJsonSerializerSetup>()
                                    .GetOrElse(NewtonSoftJsonSerializerSetup.Create(s => {}));

                settingsSetup.ApplySettings(Settings);
            }

            var converters = settings.Converters
                             .Select(type => CreateConverter(type, system))
                             .ToList();

            converters.Add(new SurrogateConverter(this));
            converters.Add(new DiscriminatedUnionConverter());

            foreach (var converter in converters)
            {
                Settings.Converters.Add(converter);
            }

            Settings.ObjectCreationHandling = ObjectCreationHandling.Replace; //important: if reuse, the serializer will overwrite properties in default references, e.g. Props.DefaultDeploy or Props.noArgs
            Settings.ContractResolver       = new AkkaContractResolver();

            _serializer = JsonSerializer.Create(Settings);
        }
예제 #3
0
 public NewtonSoftJsonSerializer(ExtendedActorSystem system, Config config)
     : this(system, NewtonSoftJsonSerializerSettings.Create(config))
 {
 }