You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the JsonSerializerOptions with converter JsonStringEnumConverter, Dapr ignore the configuration to use enum as string and:
Expect all enums to be number when subscribing
Convert enums to number when publishing
Steps to Reproduce the Problem
Use the following classes with the configuration I have put in the "Expected Behavior" section.
ObjectA
namespace Models;
public class ObjectA
{
public int Id { get; set; }
public string Name { get; set; }
public Condition Condition { get; set; }
}
Condition
namespace Models;
public enum Condition
{
New,
Used,
Refurbished
}
public static class ConditionExtensions
{
public static string? GetValue(this Condition enumValue)
{
switch (enumValue)
{
case Condition.New: return "New";
case Condition.Used: return "Used";
case Condition.Refurbished: return "Refurbished";
}
return null;
}
public static Condition? ToCondition(string? value)
{
switch (value)
{
case "New": return Condition.New;
case "Used": return Condition.Used;
case "Refurbished": return Condition.Refurbished;
}
return null;
}
}
Controller:
[Topic("pubsub", "mytopic")]
[HttpPost("/onWhatever")]
public Task<ActionResult> OnWhatever(ObjectA objectA, [FromServices] DaprClient daprClient) {
//Notice objectA will be null if you provide string instead of "int". It will be ok and deserialized properly if you provide number for the number
}
Publish
//You will notice that in the topic, the values are in integer and not string as it should be.
_daprClient.PublishEventAsync("pubsub", "mytopic", objectA);
Release Note
FIX Bug in serializer
The text was updated successfully, but these errors were encountered:
Expected Behavior
With this configuration, Dapr should expect and publish enums as string:
Actual Behavior
When using the
JsonSerializerOptions
with converterJsonStringEnumConverter
, Dapr ignore the configuration to use enum as string and:Steps to Reproduce the Problem
Use the following classes with the configuration I have put in the "Expected Behavior" section.
ObjectA
Condition
Controller:
Publish
Release Note
FIX Bug in serializer
The text was updated successfully, but these errors were encountered: