Example #1
0
        /// <summary>
        /// Static singleton function to get the JsonSerializerSettings for parsing ValidatorRule JSON objects
        /// </summary>
        /// <returns></returns>
        public static JsonSerializerSettings GetSettings()
        {
            if (_settings == null)
            {
                _settings = new JsonSerializerSettings();

                JsonSubtypesConverterBuilder builder = JsonSubtypesConverterBuilder.Of(typeof(BaseValidatorRule), BaseValidatorRule.RULE_TYPE_KEY);
                foreach (var ruleTypeToRuleCalssTypePair in _ruleTypeToRuleClassTypeMapping)
                {
                    string ruleTypeString = ruleTypeToRuleCalssTypePair.Key;
                    Type   ruleClassType  = ruleTypeToRuleCalssTypePair.Value;
                    builder = builder.RegisterSubtype(ruleClassType, ruleTypeString);
                }

                _settings.Converters.Add(builder.SerializeDiscriminatorProperty().Build());
            }

            return(_settings);
        }