2
0

JsonDefaults.cs 1023 B

12345678910111213141516171819202122232425262728293031
  1. using System.Text.Json;
  2. using System.Text.Json.Serialization;
  3. using MediaBrowser.Common.Json.Converters;
  4. namespace MediaBrowser.Common.Json
  5. {
  6. /// <summary>
  7. /// Helper class for having compatible JSON throughout the codebase.
  8. /// </summary>
  9. public static class JsonDefaults
  10. {
  11. /// <summary>
  12. /// Gets the default <see cref="JsonSerializerOptions" /> options.
  13. /// </summary>
  14. /// <returns>The default <see cref="JsonSerializerOptions" /> options.</returns>
  15. public static JsonSerializerOptions GetOptions()
  16. {
  17. var options = new JsonSerializerOptions()
  18. {
  19. ReadCommentHandling = JsonCommentHandling.Disallow,
  20. WriteIndented = false
  21. };
  22. options.Converters.Add(new JsonGuidConverter());
  23. options.Converters.Add(new JsonStringEnumConverter());
  24. options.Converters.Add(new JsonNonStringKeyDictionaryConverterFactory());
  25. return options;
  26. }
  27. }
  28. }