Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.92k stars 441 forks source link

JSON response being converted to camel casing in local environment #2873

Open dipinbehl opened 6 years ago

dipinbehl commented 6 years ago

The Azure Function serialize the result in Camel Casing when running in the local development environment while the results are serialized in Pascal Casing while running on the cloud. The same code generates different JSON result while running on development machines and on cloud.

Runtimes: -Functions Runtime Version - 2.0.11651.0 -Functions Core Tools Version - 220.0.0-beta.0

public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "TestCasing")]HttpRequest req, TraceWriter log)
{
            var result = new {PropertyName1 = "Foo", PropertyName2 = "Bar" };
            return new OkObjectResult(result);
}

When running on local development machines, it outputs the following json {"propertyName1":"Foo","propertyName2":"Bar"}

When the same code is hosted on the cloud, the following json is produced {"PropertyName1":"Foo","PropertyName2":"Bar"}

We expect the same casing in json result as defined in the response model.

ejadib commented 6 years ago

We are seeing the same, we are pretty sure this wasn't happening last week.

RohitRCondeco commented 6 years ago

This is impacting us a lot as well. Please take this up on priority.

paulbatum commented 6 years ago

I think if you're still getting this behavior you must be on an older core-tools version. I just pasted your repro code, hit F5 in VS and hit the function and I got PascalCasing:

[5/22/2018 5:14:41 PM] Starting Host (HostId=pbatumhost-717259849, InstanceId=c22a7fa5-712e-4126-9833-9ab6b864104a, Version=2.0.11776.0, ProcessId=22996, AppDomainId=1, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)

HTTP/1.1 200 OK
Date: Tue, 22 May 2018 17:17:05 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Content-Length: 45

{"PropertyName1":"Foo","PropertyName2":"Bar"}

If your version is coming out as something older than Version=2.0.11776.0 then you're not on the latest bits. This corresponds to this version of the core-tools.

dipinbehl commented 6 years ago

Thanks @paulbatum The updated runtime did resolve the issue but left us wondering as to why the casing changed when no change was made to the development environment.

paulbatum commented 6 years ago

So I'm reopening this because we screwed up and we need to fix it. Everything I said above is correct in that the current released version of the core-tools is in sync with the current bits in production Azure (at time of writing). However this casing change was wrong and we are reverting it. So you should basically expect this behavior to reverse again in the near future.

Here's the tracking issue: https://github.com/Azure/azure-functions-host/issues/2891

We'll mention this in the coming release notes. I'll close this issue once the release is complete and everything should be back into a good state.