Azure函数JsonConvert文档空间点

问题描述 投票:1回答:1

我有一个模型,其中包含一个使用Microsoft.Azure.Documents.Spatial.Point类型的属性。

public class TelemetryLiveExample
{
[JsonProperty("location")]
public Point Location { get; set; }
}

我希望能够使用Newtonsoft JsonConvert序列化和反序列化消息。例如,如果我在本地序列化以下模型。

TelemetryLiveExample telemetryLive = new TelemetryLiveExample
{
Location = new Point(1, 2)
};
JsonConvert.SerializeObject(telemetryLive);

我得到以下结果,这是我期望的Microsoft.Azure.Documents.Spatial.Point有一个自定义转换器PositionJsonConverter

"{"location":{"type":"Point","coordinates":[1.0,2.0]}}"

如果我完全相同,但首先将它发布到Azure函数,我得到以下结果。这看起来自定义转换器在Azure功能中被忽略但我无法弄清楚原因。

{"location":{"Position":{"Coordinates":[1.0,2.0],"Longitude":1.0,"Latitude":2.0,"Altitude":null},"Crs":{"Name":"urn:ogc:def:crs:OGC:1.3:CRS84","Type":0},"Type":0,"BoundingBox":null,"AdditionalProperties":{}}}

我想弄清楚为什么Azure函数序列化器忽略自定义转换器并给出不同的结果?

c# azure json.net azure-cosmosdb azure-functions
1个回答
1
投票

我想弄清楚为什么Azure函数序列化器忽略自定义转换器并给出不同的结果?

根据我的测试,azure功能和本地功能没有区别。我使用以下演示代码和nuget包Microsoft.Azure.DocumentDB进行测试。

 public static class TestDocument
    {
        [FunctionName("TestDocument")]
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {
            TelemetryLiveExample telemetryLive = new TelemetryLiveExample
            {
                Location = new Point(1, 2)
            };
            var json = JsonConvert.SerializeObject(telemetryLive);

            return req.CreateResponse(HttpStatusCode.OK, json);
        }
    }

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.