Skip to content

Commit

Permalink
Merge pull request #76 from Martijnvos/feat/add-polymorphic-type-disc…
Browse files Browse the repository at this point in the history
…riminators

Add polymorphic type discriminators
  • Loading branch information
Alkiimista authored Dec 30, 2024
2 parents afe22f1 + 65428d0 commit ba0cb72
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
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

0 comments on commit ba0cb72

Please sign in to comment.