BO4E/meta/LenientConverters/LenientJsonSerializerOptionsGenerator.cs
/// <summary>
///     Generates JsonSerializerSettings (.NET5) for given lenient parsing setting
/// </summary>
/// <param name="lenient"></param>
/// <param name="userPropertiesWhiteList"></param>
/// <returns></returns>
Generates JsonSerializerSettings (.NET5) for given lenient parsing setting
Generates JsonSerializerSettings ( . NET5 ) for given lenient parsing setting
public static JsonSerializerOptions GetJsonSerializerOptions(this LenientParsing lenient,
            HashSet<string> userPropertiesWhiteList)
        {
            var settings = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
                NumberHandling = JsonNumberHandling.AllowReadingFromString,
                Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            settings.Converters.Add(new AutoNumberToStringConverter());
            settings.Converters.Add(new VertragsConverter());
            settings.Converters.Add(new EnergiemengeConverter());
            settings.Converters.Add(new LenientSystemTextJsonStringToBoolConverter());
            settings.Converters.Add(new StringNullableEnumConverter());
            settings.Converters.Add(new JsonStringEnumConverter());
            foreach (LenientParsing lp in Enum.GetValues(typeof(LenientParsing)))
                if (lenient.HasFlag(lp))
                    switch (lp)
                    {
                        case LenientParsing.DATE_TIME:
                            if (!lenient.HasFlag(LenientParsing.SET_INITIAL_DATE_IF_NULL))
                            {
                                settings.Converters.Add(new LenientSystemTextJsonDateTimeConverter());
                                settings.Converters.Add(new LenientSystemTextJsonDateTimeOffsetConverter());
                                settings.Converters.Add(new LenientSystemTextJsonNullableDateTimeConverter());
                                settings.Converters.Add(new LenientSystemTextJsonNullableDateTimeOffsetConverter());
                            }
                            else
                            {
                                settings.Converters.Add(
                                    new LenientSystemTextJsonDateTimeConverter(new DateTimeOffset()));
                                settings.Converters.Add(
                                    new LenientSystemTextJsonNullableDateTimeConverter(new DateTimeOffset()));
                                settings.Converters.Add(
                                    new LenientSystemTextJsonDateTimeOffsetConverter(new DateTimeOffset()));
                                settings.Converters.Add(
                                    new LenientSystemTextJsonNullableDateTimeOffsetConverter(new DateTimeOffset()));
                            }
                            break;
                        case LenientParsing.ENUM_LIST:
                            settings.Converters.Add(new LenientSystemTextJsonEnumListConverter());
                            break;
                        case LenientParsing.BO4_E_URI:
                            break;
                        case LenientParsing.STRING_TO_INT:
                            settings.Converters.Add(new LenientSystemTextJsonStringToIntConverter());
                            break;
                    }
            return settings;
        }
public static JsonSerializerOptions GetJsonSerializerOptions ( this LenientParsing lenient , HashSet < string > userPropertiesWhiteList ) { var settings = new JsonSerializerOptions { PropertyNameCaseInsensitive = true , NumberHandling = JsonNumberHandling . AllowReadingFromString , Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping } ; settings . Converters . Add ( new AutoNumberToStringConverter ( ) ) ; settings . Converters . Add ( new VertragsConverter ( ) ) ; settings . Converters . Add ( new EnergiemengeConverter ( ) ) ; settings . Converters . Add ( new LenientSystemTextJsonStringToBoolConverter ( ) ) ; settings . Converters . Add ( new StringNullableEnumConverter ( ) ) ; settings . Converters . Add ( new JsonStringEnumConverter ( ) ) ; foreach ( LenientParsing lp in Enum . GetValues ( typeof ( LenientParsing ) ) ) if ( lenient . HasFlag ( lp ) ) switch ( lp ) { case LenientParsing . DATE_TIME : if ( ! lenient . HasFlag ( LenientParsing . SET_INITIAL_DATE_IF_NULL ) ) { settings . Converters . Add ( new LenientSystemTextJsonDateTimeConverter ( ) ) ; settings . Converters . Add ( new LenientSystemTextJsonDateTimeOffsetConverter ( ) ) ; settings . Converters . Add ( new LenientSystemTextJsonNullableDateTimeConverter ( ) ) ; settings . Converters . Add ( new LenientSystemTextJsonNullableDateTimeOffsetConverter ( ) ) ; } else { settings . Converters . Add ( new LenientSystemTextJsonDateTimeConverter ( new DateTimeOffset ( ) ) ) ; settings . Converters . Add ( new LenientSystemTextJsonNullableDateTimeConverter ( new DateTimeOffset ( ) ) ) ; settings . Converters . Add ( new LenientSystemTextJsonDateTimeOffsetConverter ( new DateTimeOffset ( ) ) ) ; settings . Converters . Add ( new LenientSystemTextJsonNullableDateTimeOffsetConverter ( new DateTimeOffset ( ) ) ) ; } break ; case LenientParsing . ENUM_LIST : settings . Converters . Add ( new LenientSystemTextJsonEnumListConverter ( ) ) ; break ; case LenientParsing . BO4_E_URI : break ; case LenientParsing . STRING_TO_INT : settings . Converters . Add ( new LenientSystemTextJsonStringToIntConverter ( ) ) ; break ; } return settings ; }
Generates JsonSerializerSettings (.NET5) for given lenient parsing setting
Generates JsonSerializerSettings ( . NET5 ) for given lenient parsing setting
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault //converters.Add(new LenientBo4eUriConverter()); // case LenientParsing.EmptyLists: // converters.Add(new LenientRequiredListConverter()); // break; // no default case because NONE and MOST_LENIENT do not come up with more converters //IContractResolver contractResolver; //if (userPropertiesWhiteList.Count > 0) //{ //    contractResolver = new UserPropertiesDataContractResolver(userPropertiesWhiteList); //} //else //{ //    contractResolver = new DefaultContractResolver(); //}
None
LenientParsing
this
userPropertiesWhiteList
HashSet<string>
None
lenient
None