简体   繁体   English

OData Library v3 JSON条目序列化包括:“__ metadata”:{“id”

[英]OData Library v3 JSON entry serialization includes: “__metadata”: { “id”

Using the OData Library October '11 CTP to serialize an entry using v3 I get the following: 使用OData Library October '11 CTP使用v3序列化条目我得到以下内容:

{
    "d":{
        "__metadata": {
            "id":"http://dev.foo.bar/Statuses(7)",
            "type":"Presentation.Status"
        },
        "Description":"Testing..."
    }
}

In the v3 specification the example is as follows: 在v3规范中,示例如下:

DataServiceVersion: 3.0 DataServiceVersion:3.0

{
    "d": {
        "__metadata": { 
            "uri": "Customers(\'ALFKI\')",
            "type": "SampleModel.Customer",
            ....

The specification uses _ metadata/uri and the Libary uses " _metadata/id". 规范使用_ metadata / uri, Libary 使用“ _metadata / id”。 In section [2.2.6.3.3 Entity Type (as a JSON Object)] the spec states: 在[2.2.6.3.3实体类型(作为JSON对象)]一节中,规范说明:

The JavaScript Object Notation (JSON) serialization of an EntityType instance MAY<58> include a name/value pair named "_ metadata". EntityType实例MAY <58>的JavaScript Object Notation(JSON)序列化包括名为“_ metadata”的名称/值对 This name/value pair is not data, but instead, by convention defined in this document, specifies the metadata for the EntityType instance that the JSON object represents. 此名称/值对不是数据,而是按照本文档中定义的约定,指定JSON对象表示的EntityType实例的元数据。 The ordering of this name/value pair with respect to other name/value pairs that represent properties that are defined on the Entity Type is insignificant. 此名称/值对与表示在实体类型上定义的属性的其他名称/值对的排序是无关紧要的。 In version 1.0 and version 2.0 of the OData protocol, the value of the " _metadata" property contains seven name/value pairs: "uri", "type," "etag", "edit_media", "media_src", "media_etag", and "content_type". 在OData协议的1.0版和2.0版中,“ _ metadata”属性的值包含七个名称/值对:“uri”,“type”,“etag”,“edit_media”,“media_src”,“media_etag”,和“content_type”。 In version 3.0 of the OData protocol, three more name/value pairs are added: "properties", "actions", and "functions". 在OData协议的3.0版本中,增加了三个名称/值对:“属性”,“操作”和“功能”。 The order of these name/value pairs is insignificant. 这些名称/值对的顺序无关紧要。 The value of the "uri" name/value pair MUST be the canonical URI identifying the EntityType instance represented by the JSON object. “uri”名称/值对的值必须是标识由JSON对象表示的EntityType实例的规范URI。

It looks like the current CTP of the OData library is incorrectly emitting "id", where it should be emitting "uri", as the uriNVP - as defined by: 看起来OData库的当前CTP错误地发出“id”,它应该发出“uri”,就像uriNVP一样 - 定义如下:

metadataNVP = quotation-mark "__metadata" quotation-mark
              name-seperator
              begin-object
              ( uriNVP
....

uriNVP = quotation-mark "uri" quotation-mark
             name-seperator
             quotation-mark resourcePath quotation-mark

Is the Library just incorrect - or am I missing something or using it incorrectly? 图书馆是不正确的 - 或者我错过了什么或使用不正确?

As of 5.0 RTM the JSON support is gone? 从5.0 RTM开始,JSON支持消失了吗? WTF? WTF? Why and how to get it back?? 为什么以及如何取回?

if (((ODataVersion) settings.Version) == ODataVersion.V3)
{
    specifiedTypes = RemoveApplicationJsonFromAcceptableMediaTypes(specifiedTypes, mediaTypesForPayloadKind, settings.AcceptableMediaTypes);
}

This is code from 这是来自的代码

internal static ODataFormat GetContentTypeFromSettings(ODataMessageWriterSettings settings, ODataPayloadKind payloadKind, MediaTypeResolver mediaTypeResolver, out MediaType mediaType, out Encoding encoding)

The V3 spec is not yet complete. V3规范尚未完成。 We did add the id property into the OData Library, it just didn't make it into the official spec yet. 我们确实将id属性添加到OData库中,它还没有进入官方规范。 Note that the id and uri are two different things. 请注意,id和uri是两个不同的东西。

The id property is the value of the ODataEntry.Id property. id属性是ODataEntry.Id属性的值。 It should be a globally unique URI identifying the entity. 它应该是标识实体的全局唯一URI。 It doesn't have to be a valid URL, so for example "urn:myentity:id1" is perfectly fine. 它不必是有效的URL,因此例如“urn:myentity:id1”完全没问题。 It's the same value as the id element in the ATOM representation. 它与ATOM表示中的id元素的值相同。

The uri property is the edit or read link. uri属性是编辑或读取链接。 So it's the value of the ODataEntry.EditLink or if that's null it's the vaue of the ODataEntry.ReadLink. 所以它是ODataEntry.EditLink的值,或者如果它为null,则它是ODataEntry.ReadLink的值。 This has to be a valid URL which can be used to read and/or modify the entity. 这必须是有效的URL,可用于读取和/或修改实体。

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

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