繁体   English   中英

Azure 函数 - 队列触发器将 DateTimeOffset 返回为 null

[英]Azure Function - Queue Trigger returns DateTimeOffset as null

我有一个 Azure 函数正在运行,它连接到 API,获取一些数据并将其保存到 Azure 中的队列。

然后我有另一个 Azure 函数作为该队列上的触发器运行,我在 DateTimeOffset 上遇到了一些问题? 数据中对象之一的属性。 所有其他属性都按预期工作。

简化示例代码:

运行.csx:

using System;
using System.Collections.Generic;
using GoApi;
using GoApi.Reporting.AccountTransactions;

public static void Run(ReverseFactoringTransaction myQueueItem, TraceWriter log)
{
    log.Info(myQueueItem.Transaction.CreatedDate.ToString());
    log.Info(myQueueItem.Transaction.Text.ToString());
    log.Info(myQueueItem.Transaction.Amount.ToString());
    log.Info(myQueueItem.Transaction.Date.ToString());
    log.Info(myQueueItem.Partner.Name.ToString());
    log.Info(myQueueItem.Partner.IsActive.ToString());
    log.Info(myQueueItem.Partner.CreatedDate.ToString());
    log.Info(myQueueItem.LastSynchronizationDate.ToString());
    log.Info(myQueueItem.PostOnCreatedDate.ToString());
}

public class Auditable
{
    public string CreatedBy { get; set; }
    public string UpdatedBy { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime UpdatedDate { get; set; }
}

public class Client : Auditable
{
    public Guid Id { get; set; }
    public long? CustomerId { get; set; }
    public string Name { get; set; }
    public string ClientKey { get; set; }
    public bool IsManuallyRecognized { get; set; }
    public bool IsActive { get; set; }
    public Guid PartnerId { get; set; }
    public Partner Partner { get; set; }
}

public class Partner : Auditable
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string PartnerKey { get; set; }
    public bool IsActive { get; set; }
    public List<Client> Clients { get; set; }
}

public class ReverseFactoringTransaction
{
    public Partner Partner { get; set; }
    public AccountTransaction Transaction { get; set; }
    public int ReverseAccountCode { get; set; }
    public DateTimeOffset LastSynchronizationDate { get; set; }
    public bool PostOnCreatedDate { get; set; }
}

项目.json:

{
    "frameworks":
    {
        "net46":
        {
            "dependencies":
            {
                "PowerOfficeGoSDK": "1.6.3"
            }
        }
    }
}

当我使用此测试输入时:

{
  "Partner": {
    "Id": "da462e01-d999-41d0-a71d-dbcf36ca219b",
    "Name": "Test Acme",
    "PartnerKey": "62504f06-1bee-4665-807c-6c918f2ac454",
    "IsActive": true,
    "CreatedBy": "sth",
    "UpdatedBy": "sth",
    "CreatedDate": "2017-10-18T07:40:16.3244273+00:00",
    "UpdatedDate": "2017-10-18T07:40:16.3244273+00:00"
  },
  "Transaction": {
    "Id": 4889211,
    "AccountCode": 1500,
    "Date": "2017-02-15T00:00:00",
    "VoucherNo": 14,
    "VoucherType": 4,
    "Text": "Invoice 1 for TestCompany Inc",
    "Description": "",
    "VatCode": "0",
    "VatAmount": 0.0,
    "VatRate": 0.0,
    "Amount": 380000.0,
    "CurrencyCode": "GBP",
    "CurrencyAmount": 380000.0,
    "VoucherImagesCount": 0,
    "LastChanged": "2017-10-17T15:31:14+00:00",
    "CreatedDate": "2017-10-17T15:31:14+00:00",
    "CustomerAccountNo": 10013,
    "VoucherDueDate": "2017-10-20T00:00:00",
    "VoucherCID": "141",
    "VoucherId": "95620904-623a-48b6-99a4-6316d893886b",
    "DocumentNo": "14",
    "CreatedFromImportJournalId": "1c9d60cf-9cc0-409e-9b3e-787461a0ae96",
    "IsCreatedFromEhf": false
  },
  "ReverseAccountCode": 1510,
  "LastSynchronizationDate": "2017-01-18T00:00:00+00:00",
  "PostOnCreatedDate": true,
  "$AzureWebJobsParentId": "765c4f56-0cdb-4d08-b9fa-8bc4a94e0499"
}

我得到这个作为函数的输出:

2017-10-18T08:05:50.391 Function started (Id=bb8f485c-9f33-4976-833f-4a1ac0840e22)
2017-10-18T08:05:50.391 
2017-10-18T08:05:50.391 Invoice 1 for TestCompany Inc
2017-10-18T08:05:50.391 380000.0
2017-10-18T08:05:50.391 2/15/2017 12:00:00 AM
2017-10-18T08:05:50.391 Test Acme
2017-10-18T08:05:50.391 True
2017-10-18T08:05:50.391 10/18/2017 7:40:16 AM
2017-10-18T08:05:50.391 1/18/2017 12:00:00 AM +00:00
2017-10-18T08:05:50.391 True
2017-10-18T08:05:50.391 Function completed (Success, Id=bb8f485c-9f33-4976-833f-4a1ac0840e22, Duration=1ms)

如您所见,DateTimeOffset? Transaction 对象上的 CreatedDate 显示为 null。 但我完全不知道为什么。 有谁知道是什么问题?

AccountTransaction.CreatedDate具有internal设置器,因此在反序列化期间将被忽略。

有关内部属性反序列化的说明,请参阅此问题

如果你真的需要它,你可以接受一个队列项目作为字符串,然后使用你的自定义设置/解析器手动反序列化。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM