To support Strict Mode (AZURE_FUNCTIONS_DURABLE_STRICT_TYPING=1), your custom classes must implement a symmetric to_json and from_json contract. In strict mode, to_json() must return only natively JSON-serializable types (dicts, lists, strings, numbers, bools, None), and from_json() must be able to reconstruct the object from that plain data.
Implementation Example
class Order:
@staticmethod
def to_json(obj):
# Explicitly call to_json on nested custom objects
return {
"item": obj.item,
"hat": Hat.to_json(obj.hat),
}
@staticmethod
def from_json(data):
# Reconstruct nested objects from plain dicts
return Order(
item=data["item"],
hat=Hat.from_json(data["hat"]),
)
Handling Legacy Payloads
If your application needs to support both legacy (loose-encoded) and strict-mode payloads during a transition, your from_json method should check the type of nested data:
@staticmethod
def from_json(data):
hat_data = data["hat"]
# If object_hook already fired (loose mode), hat_data is an instance
if isinstance(hat_data, Hat):
hat = hat_data
# If strict mode, hat_data is a plain dict
else:
hat = Hat.from_json(hat_data)
return Order(item=data["item"], hat=hat)
class Order:
@staticmethod
def to_json(obj):
return {
"item": obj.item,
"hat": Hat.to_json(obj.hat), # explicit — not obj.hat
}
@staticmethod
def from_json(data):
return Order(
item=data["item"],
hat=Hat.from_json(data["hat"]), # symmetric
)