Skip to content

Commit 2d6d9a0

Browse files
authored
[CustomHandler]Fix DateTime serialization (#6707)
1 parent 229df2c commit 2d6d9a0

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

release_notes.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
}
2222
```
2323
Exception is thrown if HttpOutputBindingResponse is not valid Json.
24-
25-
- Issue [#6606](https://github.com/Azure/azure-functions-host/issues/6606): We identified a couple of inconsistencies in the request schema and next release will include following changes.
26-
- Query property will change from a JSON serialized string to a dictionary
27-
- Identities property will change from a JSON serialized string to an array
24+
- We identified a couple of inconsistencies in the request schema and next release will include following changes.
25+
- Issue [#6606](https://github.com/Azure/azure-functions-host/issues/6606):
26+
- Query property will change from a JSON serialized string to a dictionary
27+
- Identities property will change from a JSON serialized string to an array
28+
- Issue [#6574](https://github.com/Azure/azure-functions-host/issues/6574)
29+
- Metadata / Input binding data of type DateTime will not be serialzed as string
2830
If you are using these properties, please ensure your app is able to detect and handle the new schema.
2931

3032
**Release sprint:** Sprint 84

src/WebJobs.Script/Workers/MessageExtensions/ScriptInvocationContextExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ internal static object GetHttpScriptInvocationContextValue(object inputValue, Da
173173
}
174174
return Convert.ToBase64String(byteArray);
175175
}
176+
if (inputValue is DateTime)
177+
{
178+
return DateTime.Parse(inputValue.ToString());
179+
}
180+
if (inputValue is DateTimeOffset)
181+
{
182+
return DateTimeOffset.Parse(inputValue.ToString());
183+
}
176184
try
177185
{
178186
return JObject.FromObject(inputValue);

test/WebJobs.Script.Tests/HttpWorker/DefaultHttpWorkerServiceTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,18 @@ private async void ValidateDefaultInvocationRequest(HttpRequestMessage httpReque
530530
Assert.Equal(expectedMetadata.Count(), httpScriptInvocationContext.Metadata.Count());
531531
foreach (var key in expectedMetadata.Keys)
532532
{
533-
Assert.Equal(JsonConvert.SerializeObject(expectedMetadata[key]), httpScriptInvocationContext.Metadata[key]);
533+
if (expectedMetadata[key] is DateTime)
534+
{
535+
Assert.Equal(DateTime.Parse(expectedMetadata[key].ToString()), httpScriptInvocationContext.Metadata[key]);
536+
}
537+
else if (expectedMetadata[key] is DateTimeOffset)
538+
{
539+
Assert.Equal(DateTimeOffset.Parse(expectedMetadata[key].ToString()), httpScriptInvocationContext.Metadata[key]);
540+
}
541+
else
542+
{
543+
Assert.Equal(JsonConvert.SerializeObject(expectedMetadata[key]), httpScriptInvocationContext.Metadata[key]);
544+
}
534545
}
535546

536547
// Verify Data

test/WebJobs.Script.Tests/HttpWorker/HttpWorkerTestUtilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static Dictionary<string, object> GetScriptInvocationBindingData()
120120
Dictionary<string, object> bindingData = new Dictionary<string, object>();
121121
bindingData["dequeueCount"] = 4;
122122
bindingData["VisibleTime"] = new DateTime(2019, 10, 1);
123+
bindingData["VisibleTimeOffset"] = new DateTimeOffset(new DateTime(2019, 10, 1));
123124
bindingData["helloString"] = "helloMetadata";
124125
return bindingData;
125126
}

0 commit comments

Comments
 (0)