Merge pull request #4730 from crobibero/base-item-dto-guid-nullable
Don't serialize empty GUID to null
This commit is contained in:
commit
b6ecaccf92
|
@ -1928,7 +1928,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||||
|
|
||||||
foreach (var programDto in currentProgramDtos)
|
foreach (var programDto in currentProgramDtos)
|
||||||
{
|
{
|
||||||
if (currentChannelsDict.TryGetValue(programDto.ChannelId, out BaseItemDto channelDto))
|
if (programDto.ChannelId.HasValue && currentChannelsDict.TryGetValue(programDto.ChannelId.Value, out BaseItemDto channelDto))
|
||||||
{
|
{
|
||||||
channelDto.CurrentProgram = programDto;
|
channelDto.CurrentProgram = programDto;
|
||||||
}
|
}
|
||||||
|
@ -2018,7 +2018,7 @@ namespace Emby.Server.Implementations.LiveTv
|
||||||
info.DayPattern = _tvDtoService.GetDayPattern(info.Days);
|
info.DayPattern = _tvDtoService.GetDayPattern(info.Days);
|
||||||
|
|
||||||
info.Name = program.Name;
|
info.Name = program.Name;
|
||||||
info.ChannelId = programDto.ChannelId;
|
info.ChannelId = programDto.ChannelId ?? Guid.Empty;
|
||||||
info.ChannelName = programDto.ChannelName;
|
info.ChannelName = programDto.ChannelName;
|
||||||
info.StartDate = program.StartDate;
|
info.StartDate = program.StartDate;
|
||||||
info.Name = program.Name;
|
info.Name = program.Name;
|
||||||
|
|
|
@ -13,21 +13,13 @@ namespace MediaBrowser.Common.Json.Converters
|
||||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
var guidStr = reader.GetString();
|
var guidStr = reader.GetString();
|
||||||
|
|
||||||
return guidStr == null ? Guid.Empty : new Guid(guidStr);
|
return guidStr == null ? Guid.Empty : new Guid(guidStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||||
{
|
|
||||||
if (value == Guid.Empty)
|
|
||||||
{
|
|
||||||
writer.WriteNullValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
writer.WriteStringValue(value);
|
writer.WriteStringValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace MediaBrowser.Model.Dto
|
||||||
/// Gets or sets the channel identifier.
|
/// Gets or sets the channel identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The channel identifier.</value>
|
/// <value>The channel identifier.</value>
|
||||||
public Guid ChannelId { get; set; }
|
public Guid? ChannelId { get; set; }
|
||||||
|
|
||||||
public string ChannelName { get; set; }
|
public string ChannelName { get; set; }
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ namespace MediaBrowser.Model.Dto
|
||||||
/// Gets or sets the parent id.
|
/// Gets or sets the parent id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The parent id.</value>
|
/// <value>The parent id.</value>
|
||||||
public Guid ParentId { get; set; }
|
public Guid? ParentId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the type.
|
/// Gets or sets the type.
|
||||||
|
@ -344,13 +344,13 @@ namespace MediaBrowser.Model.Dto
|
||||||
/// Gets or sets the series id.
|
/// Gets or sets the series id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The series id.</value>
|
/// <value>The series id.</value>
|
||||||
public Guid SeriesId { get; set; }
|
public Guid? SeriesId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the season identifier.
|
/// Gets or sets the season identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The season identifier.</value>
|
/// <value>The season identifier.</value>
|
||||||
public Guid SeasonId { get; set; }
|
public Guid? SeasonId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the special feature count.
|
/// Gets or sets the special feature count.
|
||||||
|
@ -428,7 +428,7 @@ namespace MediaBrowser.Model.Dto
|
||||||
/// Gets or sets the album id.
|
/// Gets or sets the album id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The album id.</value>
|
/// <value>The album id.</value>
|
||||||
public Guid AlbumId { get; set; }
|
public Guid? AlbumId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the album image tag.
|
/// Gets or sets the album image tag.
|
||||||
|
|
|
@ -3,7 +3,7 @@ using System.Text.Json;
|
||||||
using MediaBrowser.Common.Json.Converters;
|
using MediaBrowser.Common.Json.Converters;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Jellyfin.Common.Tests.Extensions
|
namespace Jellyfin.Common.Tests.Json
|
||||||
{
|
{
|
||||||
public class JsonGuidConverterTests
|
public class JsonGuidConverterTests
|
||||||
{
|
{
|
||||||
|
@ -44,9 +44,9 @@ namespace Jellyfin.Common.Tests.Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Serialize_EmptyGuid_Null()
|
public void Serialize_EmptyGuid_EmptyGuid()
|
||||||
{
|
{
|
||||||
Assert.Equal("null", JsonSerializer.Serialize(Guid.Empty, _options));
|
Assert.Equal($"\"{Guid.Empty}\"", JsonSerializer.Serialize(Guid.Empty, _options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user