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

Actor response object deserialization with JSON serialization results in empty objects #1459

Open
ngruson opened this issue Feb 13, 2025 · 1 comment

Comments

@ngruson
Copy link

ngruson commented Feb 13, 2025

When using actor proxies with JSON serialization, response objects of actor methods are not deserialized properly out-of-the-box.
I made a small repro.

A JSON returned by the Dapr runtime could look like this:

{
  "value":{
    "retVal":{
      "id": "166e0bbf-7084-476f-803b-c4e1418eef7e",
      "name":"John Doe"}
    }
}

with a response object defined like this:

public record Person(Guid Id, string Name);

Since the object properties are lowercased in the JSON and System.Text.Json is case sensitive by default, the properties of the Person object below are not populated.

As a workaround, I could pass in JsonSerializerOptions when initializing the actor proxy, like so:

ActorProxyOptions actorProxyOptions = new()
{
    UseJsonSerialization = true,
    JsonSerializerOptions = new JsonSerializerOptions
    {
        PropertyNameCaseInsensitive = true
    }
};


IPersonActor actorProxy = actorProxyFactory.CreateActorProxy<IPersonActor>(actorId,
    nameof(PersonActor), actorProxyOptions);

Person person = await actorProxy.ReturnPerson();

It was not immediately apparent to me that I had to set the PropertyNameCaseInsensitive property.

Question: should object properties be matched case-insensitively out-of-the-box when using the JSON serializer?
Please add your feedback in the comments.

@WhitWaldo
Copy link
Contributor

I'd generally expect the JSON object itself to just be shuffled along through the SDK and not have its property names modified anywhere, but I think it makes sense that developers would expect the case to be persisted to and from Dapr so they could provide and configure their own strictness about it.

Is this perhaps just a documentation change that calls out somewhere that if you're using the JSON serialization, there are a few default STJ considerations you should take into account (including case sensitivity)?

@WhitWaldo WhitWaldo added this to the Future milestone Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants