commit
5c57569692
@ -1,3 +1,30 @@
|
||||
{
|
||||
"Albums": "आल्बुम्"
|
||||
"Albums": "संग्रह",
|
||||
"HeaderRecordingGroups": "रिकॉर्डिंग समूह",
|
||||
"HeaderNextUp": "इसके बाद",
|
||||
"HeaderLiveTV": "लाइव टीवी",
|
||||
"HeaderFavoriteSongs": "पसंदीदा गीत",
|
||||
"HeaderFavoriteShows": "पसंदीदा शोज",
|
||||
"HeaderFavoriteEpisodes": "पसंदीदा एपिसोड्स",
|
||||
"HeaderFavoriteArtists": "पसंदीदा कलाकारसमूह",
|
||||
"HeaderFavoriteAlbums": "पसंदीदा एलबम्स",
|
||||
"HeaderContinueWatching": "देखते रहिए",
|
||||
"HeaderAlbumArtists": "एल्बम कलकरसमुह",
|
||||
"Genres": "शैली",
|
||||
"Forced": "बलपूर्वक",
|
||||
"Folders": "फोल्डेरें",
|
||||
"Favorites": "पसंदीदा",
|
||||
"FailedLoginAttemptWithUserName": "{0} से लॉगिन असफल हुआ है",
|
||||
"DeviceOnlineWithName": "{0} से संयोग हो गया है",
|
||||
"DeviceOfflineWithName": "{0} से संयोग विच्छिन्न हो गया है",
|
||||
"Default": "प्राथमिक",
|
||||
"Collections": "संग्रह",
|
||||
"ChapterNameValue": "अध्याय",
|
||||
"Channels": "चैनल",
|
||||
"CameraImageUploadedFrom": "कैमरा से एक नया चित्र अपलोड किया गया है",
|
||||
"Books": "किताब",
|
||||
"AuthenticationSucceededWithUserName": "सफलता से प्रमाणीकृत",
|
||||
"Artists": "कलाकारों",
|
||||
"Application": "एप्लिकेशन",
|
||||
"AppDeviceValues": "एप: {0}, मशीन: {1}"
|
||||
}
|
||||
|
@ -1,281 +0,0 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
|
||||
namespace Emby.Server.Implementations.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a wrapper around third party json serialization.
|
||||
/// </summary>
|
||||
public class JsonSerializer : IJsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonSerializer" /> class.
|
||||
/// </summary>
|
||||
public JsonSerializer()
|
||||
{
|
||||
ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.DateHandler.ISO8601;
|
||||
ServiceStack.Text.JsConfig.ExcludeTypeInfo = true;
|
||||
ServiceStack.Text.JsConfig.IncludeNullValues = false;
|
||||
ServiceStack.Text.JsConfig.AlwaysUseUtc = true;
|
||||
ServiceStack.Text.JsConfig.AssumeUtc = true;
|
||||
|
||||
ServiceStack.Text.JsConfig<Guid>.SerializeFn = SerializeGuid;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to stream.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
public void SerializeToStream(object obj, Stream stream)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
ServiceStack.Text.JsonSerializer.SerializeToStream(obj, obj.GetType(), stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to stream.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
public void SerializeToStream<T>(T obj, Stream stream)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
ServiceStack.Text.JsonSerializer.SerializeToStream<T>(obj, stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to file.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
public void SerializeToFile(object obj, string file)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(file))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
using (var stream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SerializeToStream(obj, stream);
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream OpenFile(string path)
|
||||
{
|
||||
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 131072);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from file.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">type</exception>
|
||||
public object DeserializeFromFile(Type type, string file)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(file))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
using (var stream = OpenFile(file))
|
||||
{
|
||||
return DeserializeFromStream(stream, type);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from file.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">file</exception>
|
||||
public T DeserializeFromFile<T>(string file)
|
||||
where T : class
|
||||
{
|
||||
if (string.IsNullOrEmpty(file))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
using (var stream = OpenFile(file))
|
||||
{
|
||||
return DeserializeFromStream<T>(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">stream</exception>
|
||||
public T DeserializeFromStream<T>(Stream stream)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromStream<T>(stream);
|
||||
}
|
||||
|
||||
public Task<T> DeserializeFromStreamAsync<T>(Stream stream)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromStreamAsync<T>(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">text</exception>
|
||||
public T DeserializeFromString<T>(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(text));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromString<T>(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">stream</exception>
|
||||
public object DeserializeFromStream(Stream stream, Type type)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream);
|
||||
}
|
||||
|
||||
public async Task<object> DeserializeFromStreamAsync(Stream stream, Type type)
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(stream));
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
using (var reader = new StreamReader(stream))
|
||||
{
|
||||
var json = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromString(json, type);
|
||||
}
|
||||
}
|
||||
|
||||
private static string SerializeGuid(Guid guid)
|
||||
{
|
||||
if (guid.Equals(Guid.Empty))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return guid.ToString("N", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from string.
|
||||
/// </summary>
|
||||
/// <param name="json">The json.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">json</exception>
|
||||
public object DeserializeFromString(string json, Type type)
|
||||
{
|
||||
if (string.IsNullOrEmpty(json))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(json));
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.DeserializeFromString(json, type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to string.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
public string SerializeToString(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
return ServiceStack.Text.JsonSerializer.SerializeToString(obj, obj.GetType());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MediaBrowser.Common.Json.Converters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a GUID object or value to/from JSON.
|
||||
/// </summary>
|
||||
public class JsonNullableGuidConverter : JsonConverter<Guid?>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Guid? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var guidStr = reader.GetString();
|
||||
return guidStr == null ? null : new Guid(guidStr);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(Utf8JsonWriter writer, Guid? value, JsonSerializerOptions options)
|
||||
{
|
||||
if (value == null || value == Guid.Empty)
|
||||
{
|
||||
writer.WriteNullValue();
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value.Value.ToString("N", CultureInfo.InvariantCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
#nullable disable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Model.Serialization
|
||||
{
|
||||
public interface IJsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializes to stream.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
void SerializeToStream(object obj, Stream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to stream.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
void SerializeToStream<T>(T obj, Stream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to file.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
void SerializeToFile(object obj, string file);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from file.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">type</exception>
|
||||
object DeserializeFromFile(Type type, string file);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from file.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="file">The file.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">file</exception>
|
||||
T DeserializeFromFile<T>(string file)
|
||||
where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">stream</exception>
|
||||
T DeserializeFromStream<T>(Stream stream);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>``0.</returns>
|
||||
/// <exception cref="ArgumentNullException">text</exception>
|
||||
T DeserializeFromString<T>(string text);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from stream.
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">stream</exception>
|
||||
object DeserializeFromStream(Stream stream, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes from string.
|
||||
/// </summary>
|
||||
/// <param name="json">The json.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
/// <exception cref="ArgumentNullException">json</exception>
|
||||
object DeserializeFromString(string json, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Serializes to string.
|
||||
/// </summary>
|
||||
/// <param name="obj">The obj.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
/// <exception cref="ArgumentNullException">obj</exception>
|
||||
string SerializeToString(object obj);
|
||||
|
||||
Task<object> DeserializeFromStreamAsync(Stream stream, Type type);
|
||||
Task<T> DeserializeFromStreamAsync<T>(Stream stream);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using MediaBrowser.Common.Json.Converters;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Common.Tests.Json
|
||||
{
|
||||
public class JsonNullableGuidConverterTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _options;
|
||||
|
||||
public JsonNullableGuidConverterTests()
|
||||
{
|
||||
_options = new JsonSerializerOptions();
|
||||
_options.Converters.Add(new JsonNullableGuidConverter());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_Valid_Success()
|
||||
{
|
||||
Guid? value = JsonSerializer.Deserialize<Guid?>(@"""a852a27afe324084ae66db579ee3ee18""", _options);
|
||||
Assert.Equal(new Guid("a852a27afe324084ae66db579ee3ee18"), value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_ValidDashed_Success()
|
||||
{
|
||||
Guid? value = JsonSerializer.Deserialize<Guid?>(@"""e9b2dcaa-529c-426e-9433-5e9981f27f2e""", _options);
|
||||
Assert.Equal(new Guid("e9b2dcaa-529c-426e-9433-5e9981f27f2e"), value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Roundtrip_Valid_Success()
|
||||
{
|
||||
Guid guid = new Guid("a852a27afe324084ae66db579ee3ee18");
|
||||
string value = JsonSerializer.Serialize(guid, _options);
|
||||
Assert.Equal(guid, JsonSerializer.Deserialize<Guid?>(value, _options));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_Null_EmptyGuid()
|
||||
{
|
||||
Assert.Null(JsonSerializer.Deserialize<Guid?>("null", _options));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_EmptyGuid_EmptyGuid()
|
||||
{
|
||||
Assert.Equal("null", JsonSerializer.Serialize((Guid?)Guid.Empty, _options));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_Valid_NoDash_Success()
|
||||
{
|
||||
var guid = (Guid?)new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
||||
var str = JsonSerializer.Serialize(guid, _options);
|
||||
Assert.Equal($"\"{guid:N}\"", str);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_Nullable_Success()
|
||||
{
|
||||
Guid? guid = new Guid("531797E9-9457-40E0-88BC-B1D6D38752FA");
|
||||
var str = JsonSerializer.Serialize(guid, _options);
|
||||
Assert.Equal($"\"{guid:N}\"", str);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue