Guest User

Untitled

a guest
Oct 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. using Amazon.Lambda.Core;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Serialization;
  4.  
  5. [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
  6. namespace LambdaDemo.ProxyLambda
  7. {
  8. public class Function
  9. {
  10. public string FunctionHandler(InputModel input, ILambdaContext context)
  11. {
  12. Console.WriteLine($"input: {input.ToJson()}");
  13.  
  14. var output = new OutputModel()
  15. {
  16. UserId = input.UserId,
  17. UserName = "BEACHSIDE" //とりあえず...
  18. };
  19.  
  20. return output.ToJson();
  21. }
  22.  
  23. }
  24.  
  25. // 入力用 model
  26. public class InputModel : BaseDemoModel
  27. {
  28. public string UserId { get; set; }
  29. }
  30.  
  31. // 出力用 model
  32. public class OutputModel : BaseDemoModel
  33. {
  34. public string UserId { get; set; }
  35. public string UserName { get; set; }
  36. }
  37.  
  38. // キャメルケースでjsonを返すためだけの base class
  39. public abstract class BaseDemoModel
  40. {
  41. private static readonly JsonSerializerSettings Settings;
  42.  
  43. static BaseDemoModel()
  44. {
  45. Settings = new JsonSerializerSettings
  46. {
  47. ContractResolver = new CamelCasePropertyNamesContractResolver(),
  48. };
  49. }
  50. public virtual string ToJson() => JsonConvert.SerializeObject(this, Settings);
  51.  
  52. }
  53. }
Add Comment
Please, Sign In to add comment