Open hossam-nasr opened 1 year ago
Discussed offline. Let's make sure to update the docs here: https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-serialization-and-persistence?tabs=javascript to make it clearer this isn't a supported scenario, and let's discuss whether this is a feature we want to invest time in. For now, doesn't seem pressing/related to v3 preview
If you try to set a durable entity state to a non-serializable object, for example a rich class, the methods of that class would not be available and your entity/orchestration would fail with an error. The simplest example of this is the
ShoppingEntity
/ShoppingOrchestration
example in thesamples/
directory:ShoppingEntity/index.ts
:ShoppingOrchestration/index.ts
:ShoppingCart
class definition:Attempting to call the above
ShoppingOrchestration
orchestration actually doesn't work, and fails becausecart.addItem()
isn't a function (it is lost after serialization/deserialization). For obvious reasons, entity states can only be JSON-serializable values, since they have to be serialized/deserialized to be written to storage.What I would recommend:
Alternatively, we could try to think about how we could make a rich class use-case work. For example, we could have a way for a user to provide a class constructor to the state initializer, and call that constructor every time we retrieve the state. This may still not cover every use-case though. More investigation and design would be required to see what makes sense here and if it's worth it.