Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Polymorphism does not work properly #55

Open
pipalmic opened this issue Oct 25, 2021 · 1 comment
Open

Polymorphism does not work properly #55

pipalmic opened this issue Oct 25, 2021 · 1 comment

Comments

@pipalmic
Copy link

I am trying to use a combo of Orleans, Orleans transactions, CosmosDB and polymorphism in my application.

So far I came up to the conclusion that the only way to make polymorphism work is to pass CosmosClient with a custom CosmosSerializer (just copied native implementation with proper TypeHandling) into the storage provider during the initialization. All the other attempts failed as JsonSerializerSettings and TypeHandling values of CosmosDBStorageOptions are ignored during the WriteStateAsync.

However, this custom CosmosClient has one drawback (or maybe a feature). During ReadStateAsync, the value of the State field has already the correct type (in case of Orleans transactions, the state is of TransactionalStateRecord type) when returned from CosmosClient whereas, without the custom implementation, the type of the State is JsonObject. This fact is causing an error on this line as .ToString() returns just a type name on TransactionalStateRecord, not a valid JSON.

grainState.State = JsonConvert.DeserializeObject(doc.Resource.State.ToString(), grainState.State.GetType(), this._options.JsonSerializerSettings);

Fixing is possible by checking if the type is JsonObject (do the current logic) or something else (set the state directly without deserialization) which I can do. However, I don't think this is the most beautiful solution in the world, haven't you already investigated a similar issue? Could be there some other pitfalls?

@pipalmic
Copy link
Author

The second thing here is that because of this extra step, there could always be a different JsonSettings configuration during serialization (WriteState doesn't use JsonSerializerSettings, just default CosmosClient values) and deserialization (that quoted row is using JsonSerializerSettings).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant