@@ -30,6 +30,7 @@ public class NodeFunctionInvoker : FunctionInvokerBase
30
30
private readonly Collection < FunctionBinding > _outputBindings ;
31
31
private readonly string _script ;
32
32
private readonly DictionaryJsonConverter _dictionaryJsonConverter = new DictionaryJsonConverter ( ) ;
33
+ private static readonly ExpandoObjectJsonConverter _expandoObjectJsonConverter = new ExpandoObjectJsonConverter ( ) ;
33
34
private readonly BindingMetadata _trigger ;
34
35
private readonly IMetricsLogger _metrics ;
35
36
private readonly string _entryPoint ;
@@ -186,7 +187,7 @@ private async Task ProcessInputBindingsAsync(Binder binder, Dictionary<string, o
186
187
executionContext [ "_inputs" ] = inputs ;
187
188
}
188
189
189
- private static async Task ProcessOutputBindingsAsync ( Collection < FunctionBinding > outputBindings , object input , Binder binder ,
190
+ private static async Task ProcessOutputBindingsAsync ( Collection < FunctionBinding > outputBindings , object input , Binder binder ,
190
191
Dictionary < string , object > bindingData , Dictionary < string , object > scriptExecutionContext , object functionResult )
191
192
{
192
193
if ( outputBindings == null )
@@ -212,11 +213,7 @@ private static async Task ProcessOutputBindingsAsync(Collection<FunctionBinding>
212
213
object value = null ;
213
214
if ( bindings . TryGetValue ( binding . Metadata . Name , out value ) && value != null )
214
215
{
215
- if ( value . GetType ( ) == typeof ( ExpandoObject ) ||
216
- ( value is Array && value . GetType ( ) != typeof ( byte [ ] ) ) )
217
- {
218
- value = JsonConvert . SerializeObject ( value ) ;
219
- }
216
+ value = ConvertBindingValue ( value ) ;
220
217
221
218
BindingContext bindingContext = new BindingContext
222
219
{
@@ -230,6 +227,23 @@ private static async Task ProcessOutputBindingsAsync(Collection<FunctionBinding>
230
227
}
231
228
}
232
229
230
+ /// <summary>
231
+ /// Perform any necessary conversions on the binding value received
232
+ /// from the script.
233
+ /// </summary>
234
+ internal static object ConvertBindingValue ( object value )
235
+ {
236
+ if ( value . GetType ( ) == typeof ( ExpandoObject ) ||
237
+ ( value is Array && value . GetType ( ) != typeof ( byte [ ] ) ) )
238
+ {
239
+ // objects and arrays we serialize to string before
240
+ // passing to the binding layer
241
+ value = JsonConvert . SerializeObject ( value , _expandoObjectJsonConverter ) ;
242
+ }
243
+
244
+ return value ;
245
+ }
246
+
233
247
protected override void OnScriptFileChanged ( object sender , FileSystemEventArgs e )
234
248
{
235
249
if ( _scriptFunc == null )
@@ -274,7 +288,7 @@ private Dictionary<string, object> CreateScriptExecutionContext(object input, Da
274
288
// TraceWriter. Might happen if a function tries to
275
289
// log after calling done()
276
290
}
277
- }
291
+ }
278
292
279
293
return Task . FromResult < object > ( null ) ;
280
294
} ) ;
@@ -393,12 +407,12 @@ private static Dictionary<string, object> NormalizeBindingData(Dictionary<string
393
407
return normalizedBindingData ;
394
408
}
395
409
396
- private static bool IsEdgeSupportedType ( Type type )
410
+ internal static bool IsEdgeSupportedType ( Type type )
397
411
{
398
- if ( type == typeof ( int ) ||
399
- type == typeof ( double ) ||
400
- type == typeof ( string ) ||
401
- type == typeof ( bool ) ||
412
+ if ( type == typeof ( int ) ||
413
+ type == typeof ( double ) ||
414
+ type == typeof ( string ) ||
415
+ type == typeof ( bool ) ||
402
416
type == typeof ( byte [ ] ) ||
403
417
type == typeof ( object [ ] ) )
404
418
{
0 commit comments