@@ -30,6 +30,7 @@ public class NodeFunctionInvoker : FunctionInvokerBase
3030 private readonly Collection < FunctionBinding > _outputBindings ;
3131 private readonly string _script ;
3232 private readonly DictionaryJsonConverter _dictionaryJsonConverter = new DictionaryJsonConverter ( ) ;
33+ private static readonly ExpandoObjectJsonConverter _expandoObjectJsonConverter = new ExpandoObjectJsonConverter ( ) ;
3334 private readonly BindingMetadata _trigger ;
3435 private readonly IMetricsLogger _metrics ;
3536 private readonly string _entryPoint ;
@@ -186,7 +187,7 @@ private async Task ProcessInputBindingsAsync(Binder binder, Dictionary<string, o
186187 executionContext [ "_inputs" ] = inputs ;
187188 }
188189
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 ,
190191 Dictionary < string , object > bindingData , Dictionary < string , object > scriptExecutionContext , object functionResult )
191192 {
192193 if ( outputBindings == null )
@@ -212,11 +213,7 @@ private static async Task ProcessOutputBindingsAsync(Collection<FunctionBinding>
212213 object value = null ;
213214 if ( bindings . TryGetValue ( binding . Metadata . Name , out value ) && value != null )
214215 {
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 ) ;
220217
221218 BindingContext bindingContext = new BindingContext
222219 {
@@ -230,6 +227,23 @@ private static async Task ProcessOutputBindingsAsync(Collection<FunctionBinding>
230227 }
231228 }
232229
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+
233247 protected override void OnScriptFileChanged ( object sender , FileSystemEventArgs e )
234248 {
235249 if ( _scriptFunc == null )
@@ -274,7 +288,7 @@ private Dictionary<string, object> CreateScriptExecutionContext(object input, Da
274288 // TraceWriter. Might happen if a function tries to
275289 // log after calling done()
276290 }
277- }
291+ }
278292
279293 return Task . FromResult < object > ( null ) ;
280294 } ) ;
@@ -393,12 +407,12 @@ private static Dictionary<string, object> NormalizeBindingData(Dictionary<string
393407 return normalizedBindingData ;
394408 }
395409
396- private static bool IsEdgeSupportedType ( Type type )
410+ internal static bool IsEdgeSupportedType ( Type type )
397411 {
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 ) ||
402416 type == typeof ( byte [ ] ) ||
403417 type == typeof ( object [ ] ) )
404418 {
0 commit comments