-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from manuc66/feature/handleDifferentPropertyNa…
…meCase Handle different type property name case
- Loading branch information
Showing
6 changed files
with
182 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using NUnit.Framework; | ||
|
||
namespace JsonSubTypes.Tests | ||
{ | ||
|
||
public class TypePropertyCase | ||
{ | ||
public class TypePropertyCase_LowerWithHigher | ||
{ | ||
[JsonConverter(typeof(JsonSubtypes), "msgType")] | ||
[JsonSubtypes.KnownSubType(typeof(Foo), 1)] | ||
public abstract class DtoBase | ||
{ | ||
public virtual int MsgType { get; set; } | ||
} | ||
|
||
class Foo : DtoBase | ||
{ | ||
} | ||
|
||
[Test] | ||
public void FooParsingCamelCase() | ||
{ | ||
var serializeObject = "{\"MsgType\":1}"; | ||
var msgType = JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType; | ||
Assert.AreEqual(1, msgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
|
||
[Test] | ||
public void FooParsingLowerPascalCase() | ||
{ | ||
var serializeObject = "{\"msgType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
} | ||
|
||
public class TypePropertyCase_HigherWithLower | ||
{ | ||
[JsonConverter(typeof(JsonSubtypes), "MsgType")] | ||
[JsonSubtypes.KnownSubType(typeof(Foo), 1)] | ||
public abstract class DtoBase | ||
{ | ||
[JsonProperty("msgType")] | ||
public virtual int MsgType { get; set; } | ||
} | ||
|
||
class Foo : DtoBase | ||
{ | ||
} | ||
|
||
[Test] | ||
public void FooParsingCamelCase() | ||
{ | ||
var serializeObject = "{\"MsgType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
|
||
[Test] | ||
public void FooParsingLowerPascalCase() | ||
{ | ||
var serializeObject = "{\"msgType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
} | ||
|
||
public class TypePropertyCase_RedirectLowerWithHigher | ||
{ | ||
[JsonConverter(typeof(JsonSubtypes), "messageType")] | ||
[JsonSubtypes.KnownSubType(typeof(Foo), 1)] | ||
public abstract class DtoBase | ||
{ | ||
[JsonProperty("MessageType")] | ||
public virtual int MsgType { get; set; } | ||
} | ||
|
||
class Foo : DtoBase | ||
{ | ||
} | ||
|
||
[Test] | ||
public void FooParsingCamelCase() | ||
{ | ||
var serializeObject = "{\"MessageType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
|
||
[Test] | ||
public void FooParsingLowerPascalCase() | ||
{ | ||
var serializeObject = "{\"messageType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
} | ||
|
||
public class TypePropertyCase_RedirectHigherWithLower | ||
{ | ||
[JsonConverter(typeof(JsonSubtypes), "MessageType")] | ||
[JsonSubtypes.KnownSubType(typeof(Foo), 1)] | ||
public abstract class DtoBase | ||
{ | ||
[JsonProperty("messageType")] | ||
public virtual int MsgType { get; set; } | ||
} | ||
|
||
class Foo : DtoBase | ||
{ | ||
} | ||
|
||
[Test] | ||
public void FooParsingCamelCase() | ||
{ | ||
var serializeObject = "{\"MessageType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
|
||
[Test] | ||
public void FooParsingLowerPascalCase() | ||
{ | ||
var serializeObject = "{\"messageType\":1}"; | ||
Assert.AreEqual(1, JsonConvert.DeserializeObject<Foo>(serializeObject).MsgType); | ||
Assert.IsInstanceOf<Foo>(JsonConvert.DeserializeObject<DtoBase>(serializeObject)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters