Azure / Azure-Functions

1.11k stars 195 forks source link

Azure Functions V3 Dynamic Serialization #1438

Open DanielClausen opened 4 years ago

DanielClausen commented 4 years ago

I've got an azure functions project that takes in an object that has a dynamic property, stores it into cosmos and reads that same object out and returns it as JSON from a HTTPTrigger. Since upgrading to V3 my dynamic property is now malformed in the response.

    {
        "id": "ck4cn5aox0000s83ab0jwwvl6",
        "name": "survey1",
        "clientId": 14,
        "revisionNumber": 0,
        "datasets": [
            "managers",
            "techs"
        ],
        "sections": [
            {
                "name": [],
                "items": [
                    {
                        "prompt": [],
                        "type": [],
                        "name": [],
                        "validators": [
                            []
                        ],
                        "optionsFrom": [],
                        "allowOther": []
                    }]
            }
        ]
    }
]

The sections property is type dynamic and as you can see every property is being returned as an empty array. The nested properties "name", "prompt", "type", etc should be strings, not arrays. The primitive values on the root object serialize fine.

If I downgrade back to functions V2 the JSON serialization works properly I haven't found any documentation that explicitly states that V3 uses the new system.text.json classes I know ASP.Net core has and as AZ Functions is built on top of it's likely it has as well. So my guess is this problem is related to the following: https://github.com/dotnet/corefx/issues/38007.

Seeing as Microsoft doesn't plan to support dynamics in System.Text.Json anytime soon we need a way to switch back to NewtonsoftJson. In ASP.Net core you can switch back by adding services.AddControllers().AddNewtonsoftJson() to Startup. It would be helpful for Azure Functions to have some equivalent.

ErikAndreas commented 4 years ago

same issue here but using dynamic as type to proxy response (from API called by function) to frontend application, don't really care for creating API response specific model, dynamic is (should be!) just fine!