deepgram / deepgram-dotnet-sdk

.NET SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
30 stars 31 forks source link

JSON Deserialization broken for Deepgram.Models.Listen.v1.REST.Warning #329

Closed mchernoff closed 3 weeks ago

mchernoff commented 3 weeks ago

What is the current behavior?

When deserializing the response body in the Deepgram PreRecorded callback, (Deepgram.Models.Listen.v1.REST.SyncResponse), the following exception is thrown:

The JSON value could not be converted to System.Nullable`1[Deepgram.Constants.WarningType]. Path: $.metadata.warnings[0].type | LineNumber: 0 | BytePositionInLine: 88.'

This seems to be due to the WarningType class using System.Runtime.Serialization.EnumMember attributes to specify key name, which is not supported in System.Text.Json.

Newtonsoft.Json is able to handle this enum, but that package is not compatible with the rest of the data contract, since it uses System.Text.Serialization annotations. For example, the Word.HeardWord property is not deserialized by Newtonsoft since its JSON property name is "word".

Steps to reproduce

Shortened JSON body for example:

var json = "{ \"metadata\": { \"warnings\": [ { \"parameter\": \"sentiment\", \"type\": \"unsupported_language\", \"message\": \"Sentiment is only supported for English.\" } ] } }";
var result = System.Text.Json.JsonSerializer.Deserialize<Deepgram.Models.Listen.v1.REST.SyncResponse>(json);

Expected behavior

Correctly deserializes into a SyncResponse class using System.Text.Json.

Please tell us about your environment

.NET 6 Deepgram SDK v4.3.2

dvonthenen commented 3 weeks ago

Looking into this! thanks for the bug report @mchernoff

dvonthenen commented 3 weeks ago

hi @mchernoff

There is a PR open to address this. I think this is good compromise to addressing the issue. Please take a look: https://github.com/deepgram/deepgram-dotnet-sdk/pull/331

dvonthenen commented 3 weeks ago

this should be available shortly: https://github.com/deepgram/deepgram-dotnet-sdk/releases/tag/4.3.3

mchernoff commented 2 weeks ago

Thank you for looking into this and resolving so quickly!