Skip to content

Commit

Permalink
Added types to json to enable derived type deserialization.
Browse files Browse the repository at this point in the history
  • Loading branch information
NTDLS committed Jan 3, 2024
1 parent b4caf0a commit c47df38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion NTDLS.StreamFraming/FrameBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class FrameBody
public FrameBody(IFramePayload framePayload)
{
ObjectType = framePayload.GetType()?.AssemblyQualifiedName ?? string.Empty;
Bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(framePayload));
Bytes = Encoding.UTF8.GetBytes(Utility.JsonSerialize(framePayload));
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions NTDLS.StreamFraming/NTDLS.StreamFraming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<RepositoryUrl>https://github.com/NTDLS/NTDLS.StreamFraming</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<PackageReleaseNotes>
Added QueryAsync().
Added types to json to enable derived type deserialization.
</PackageReleaseNotes>
<AssemblyVersion>1.2.3</AssemblyVersion>
<FileVersion>1.2.3</FileVersion>
<VersionPrefix>1.2.3</VersionPrefix>
<AssemblyVersion>1.2.4</AssemblyVersion>
<FileVersion>1.2.4</FileVersion>
<VersionPrefix>1.2.4</VersionPrefix>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageTags>stream;framing;tcpip;io;</PackageTags>
<IncludeSymbols>False</IncludeSymbols>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>$(VersionPrefix)</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand Down
10 changes: 9 additions & 1 deletion NTDLS.StreamFraming/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace NTDLS.StreamFraming
{
internal static class Utility
{
private static readonly JsonSerializerSettings _jsonSettings = new()
{
TypeNameHandling = TypeNameHandling.All
};

[MethodImpl(MethodImplOptions.NoInlining)]
public static string GetCurrentMethod()
{
Expand Down Expand Up @@ -101,8 +106,11 @@ public static byte[] SerializeToByteArray(object obj)
return stream.ToArray();
}

public static string JsonSerialize<T>(T obj)
=> JsonConvert.SerializeObject(obj, _jsonSettings);

public static T? JsonDeserializeToObject<T>(string json)
=> JsonConvert.DeserializeObject<T>(json);
=> JsonConvert.DeserializeObject<T>(json, _jsonSettings);

public static T DeserializeToObject<T>(byte[] arrBytes)
{
Expand Down

0 comments on commit c47df38

Please sign in to comment.