Skip to content

Commit 62d53de

Browse files
authored
Merge pull request #152 from manuc66/feature/fix_SetFallbackSubtype
Fix call SetFallbackSubtype<T>() #147
2 parents 383f42d + 43aa750 commit 62d53de

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

JsonSubTypes.Tests/DynamicRegisterTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,23 @@ public void TestFallBack()
384384
Assert.AreEqual("False", (expr as UnknownExpression)?.Type);
385385
}
386386

387+
[Test]
388+
public void TestFallBackGeneric()
389+
{
390+
var settings = new JsonSerializerSettings();
391+
JsonConvert.DefaultSettings = () => settings;
392+
393+
settings.Converters.Add(JsonSubtypesConverterBuilder
394+
.Of(typeof(IExpression), "Type")
395+
.SetFallbackSubtype<UnknownExpression>()
396+
.RegisterSubtype(typeof(ConstantExpression), "Constant")
397+
.Build());
398+
399+
var expr = JsonConvert.DeserializeObject<IExpression>("{\"Type\": \"False\"}");
400+
401+
Assert.AreEqual("False", (expr as UnknownExpression)?.Type);
402+
}
403+
387404
[Test]
388405
public void TestFallBackWithNullRegistered()
389406
{

JsonSubTypes/JsonSubtypesConverterBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public JsonSubtypesConverterBuilder SetFallbackSubtype(Type fallbackSubtype)
7878
return this;
7979
}
8080

81-
public JsonSubtypesConverterBuilder SetFallbackSubtype<T>(object value)
81+
public JsonSubtypesConverterBuilder SetFallbackSubtype<T>()
8282
{
83-
return RegisterSubtype(typeof(T), value);
83+
return SetFallbackSubtype(typeof(T));
8484
}
8585

8686
public JsonConverter Build()

0 commit comments

Comments
 (0)