Skip to content

Commit 6004faa

Browse files
Merge remote-tracking branch 'origin/master' into scheduler/fix
2 parents a5fc237 + 5d71f00 commit 6004faa

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/JsonRpc/Serialization/Converters/EnumLikeStringConverter.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ public override IEnumLikeString ReadJson(
1313
bool hasExistingValue,
1414
JsonSerializer serializer
1515
) =>
16-
reader.TokenType switch {
17-
JsonToken.String => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value),
18-
_ => (IEnumLikeString) Activator.CreateInstance(objectType, null)
16+
( reader.TokenType, Nullable.GetUnderlyingType(objectType) ) switch {
17+
(JsonToken.String, null) => (IEnumLikeString) Activator.CreateInstance(objectType, (string) reader.Value),
18+
(JsonToken.String, { } realType) => (IEnumLikeString) Activator.CreateInstance(realType, (string) reader.Value),
19+
(_, { }) => (IEnumLikeString) Activator.CreateInstance(objectType, null),
20+
_ => null
1921
};
2022

2123
public override bool CanRead => true;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using FluentAssertions;
3+
using OmniSharp.Extensions.DebugAdapter.Client;
4+
using OmniSharp.Extensions.DebugAdapter.Protocol;
5+
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
6+
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
7+
using Xunit;
8+
9+
namespace Dap.Tests
10+
{
11+
public class EnumLikeConverterTests
12+
{
13+
[Fact]
14+
public void PathFormat_Should_Be_Serializable()
15+
{
16+
var options = new InitializeRequestArguments() {
17+
PathFormat = PathFormat.Uri
18+
};
19+
20+
Action a = () => new DapSerializer().SerializeObject(options);
21+
a.Should().NotThrow();
22+
}
23+
[Fact]
24+
public void PathFormat_Should_Be_Deserializable()
25+
{
26+
Func<InitializeRequestArguments> a = () => new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\": \"Uri\"}");
27+
a.Should().NotThrow().Subject.PathFormat.Should().NotBeNull();
28+
}
29+
[Fact]
30+
public void PathFormat_Should_Be_Deserializable_When_Null()
31+
{
32+
var a = new DapSerializer().DeserializeObject<InitializeRequestArguments>("{\"pathformat\":null}");
33+
a.PathFormat.Should().BeNull();
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)