Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add polymorphic type discriminators #76

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.10.0] - 2024-12-30
### Added
- Polymorphic type discriminators on IRichMessage for deserialization

### Changed
- Updated `System.Text.Json` to 8.0.5 fixing a [high impact security vulnerability](https://github.com/advisories/GHSA-hh2w-p6rv-4g7w)

## [2.9.0] - 2024-06-20
### Changed
- New global messaging endpoint
Expand Down
23 changes: 23 additions & 0 deletions CM.Text.Tests/DeserializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json;
using CM.Text.BusinessMessaging.Model.MultiChannel;
using FluentAssertions;

namespace CM.Text.Tests
{
[TestClass]
public class DeserializationTests
{
[TestMethod]
public void DeserializeTextTest()
{
var textMessage = "{\"$type\":\"TextMessage\",\"text\":\"testing correct deserialization\",\"tag\":null,\"suggestions\":null}";
var deserialized = JsonSerializer.Deserialize<IRichMessage>(textMessage);

deserialized.Should().BeOfType<TextMessage>();
var deserializedTextMessage = deserialized as TextMessage;
deserializedTextMessage!.Text.Should().Be("testing correct deserialization");
}
}
}


20 changes: 20 additions & 0 deletions CM.Text.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json;
using CM.Text.BusinessMessaging.Model.MultiChannel;
using FluentAssertions;

namespace CM.Text.Tests
{
[TestClass]
public class SerializationTests
{
[TestMethod]
public void SerializeTextTest()
{
var textMessage = new TextMessage("testing correct serialization");
var serialized= JsonSerializer.Serialize<IRichMessage>(textMessage);

serialized.Should().NotBeNullOrWhiteSpace();
serialized.Should().Contain("\"$type\":\"TextMessage\"");
}
}
}
16 changes: 8 additions & 8 deletions CM.Text/BusinessMessaging/Model/MultiChannel/IRichMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace CM.Text.BusinessMessaging.Model.MultiChannel
/// Requires a json derived type for serialization to work
/// </summary>
[PublicAPI]
[JsonDerivedType(typeof(MediaMessage))]
[JsonDerivedType(typeof(ApplePayRequest))]
[JsonDerivedType(typeof(CarouselMessage))]
[JsonDerivedType(typeof(ContactMessage))]
[JsonDerivedType(typeof(LocationPushMessage))]
[JsonDerivedType(typeof(TemplateMessage))]
[JsonDerivedType(typeof(TextMessage))]
[JsonDerivedType(typeof(WhatsAppInteractiveMessage))]
[JsonDerivedType(typeof(MediaMessage), nameof(MediaMessage))]
[JsonDerivedType(typeof(ApplePayRequest), nameof(ApplePayRequest))]
[JsonDerivedType(typeof(CarouselMessage), nameof(CarouselMessage))]
[JsonDerivedType(typeof(ContactMessage), nameof(ContactMessage))]
[JsonDerivedType(typeof(LocationPushMessage), nameof(LocationPushMessage))]
[JsonDerivedType(typeof(TemplateMessage), nameof(TemplateMessage))]
[JsonDerivedType(typeof(TextMessage), nameof(TextMessage))]
[JsonDerivedType(typeof(WhatsAppInteractiveMessage), nameof(WhatsAppInteractiveMessage))]
public interface IRichMessage
{
}
Expand Down
8 changes: 4 additions & 4 deletions CM.Text/CM.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md"))</PackageReleaseNotes>
<Version>2.9.0</Version>
<Version>2.10.0</Version>
<PackageProjectUrl>https://github.com/cmdotcom/text-sdk-dotnet</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyVersion>2.9.0</AssemblyVersion>
<FileVersion>2.9.0</FileVersion>
<AssemblyVersion>2.10.0</AssemblyVersion>
<FileVersion>2.10.0</FileVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down Expand Up @@ -63,7 +63,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading