-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionTestJsonOutput.cs
57 lines (48 loc) · 1.64 KB
/
FunctionTestJsonOutput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace FunctionAppJsonError
{
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public static class FunctionTestJsonOutput
{
[FunctionName("FunctionTestJsonOutput")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var foo = new Foo("Has value");
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
var options = new JsonSerializerOptions
{
IgnoreNullValues = true,
};
return new JsonResult(foo, settings);
}
public enum Status
{
Pending,
Completed
}
public class Foo
{
public Foo(string withValue)
{
this.WithValue = withValue;
}
[JsonConverter(typeof(StringEnumConverter))]
public Status Status { get; set; }
public string WithValue { get; set; }
public string NullValue { get; set; }
}
}
}