Skip to content

Commit 61ace95

Browse files
authored
[CustomHandler]Fix DateTime serialization (#6707) (#6710)
1 parent c9114e9 commit 61ace95

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
@@ -125,6 +125,14 @@ internal static object GetHttpScriptInvocationContextValue(object inputValue, Da
125125
}
126126
return Convert.ToBase64String(byteArray);
127127
}
128+
if (inputValue is DateTime)
129+
{
130+
return DateTime.Parse(inputValue.ToString());
131+
}
132+
if (inputValue is DateTimeOffset)
133+
{
134+
return DateTimeOffset.Parse(inputValue.ToString());
135+
}
128136
try
129137
{
130138
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
@@ -513,7 +513,18 @@ private async void ValidateDefaultInvocationRequest(HttpRequestMessage httpReque
513513
Assert.Equal(expectedMetadata.Count(), httpScriptInvocationContext.Metadata.Count());
514514
foreach (var key in expectedMetadata.Keys)
515515
{
516-
Assert.Equal(JsonConvert.SerializeObject(expectedMetadata[key]), httpScriptInvocationContext.Metadata[key]);
516+
if (expectedMetadata[key] is DateTime)
517+
{
518+
Assert.Equal(DateTime.Parse(expectedMetadata[key].ToString()), httpScriptInvocationContext.Metadata[key]);
519+
}
520+
else if (expectedMetadata[key] is DateTimeOffset)
521+
{
522+
Assert.Equal(DateTimeOffset.Parse(expectedMetadata[key].ToString()), httpScriptInvocationContext.Metadata[key]);
523+
}
524+
else
525+
{
526+
Assert.Equal(JsonConvert.SerializeObject(expectedMetadata[key]), httpScriptInvocationContext.Metadata[key]);
527+
}
517528
}
518529

519530
// 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)