Using the OData Library October ’11 CTP to serialize an entry using v3 I get the following:
{
"d":{
"__metadata": {
"id":"http://dev.foo.bar/Statuses(7)",
"type":"Presentation.Status"
},
"Description":"Testing..."
}
}
In the v3 specification the example is as follows:
DataServiceVersion: 3.0
{
"d": {
"__metadata": {
"uri": "Customers(\'ALFKI\')",
"type": "SampleModel.Customer",
....
The specification uses _metadata/uri and the Libary uses “_metadata/id”. In section [2.2.6.3.3 Entity Type (as a JSON Object)] the spec states:
The JavaScript Object Notation (JSON) serialization of an EntityType
instance MAY<58> include a name/value pair named “_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. 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”. In
version 3.0 of the OData protocol, three more name/value pairs are
added: “properties”, “actions”, and “functions”. 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.
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:
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?
The V3 spec is not yet complete. We did add the id property into the OData Library, it just didn’t make it into the official spec yet. Note that the id and uri are two different things.
The id property is the value of the ODataEntry.Id property. It should be a globally unique URI identifying the entity. It doesn’t have to be a valid URL, so for example “urn:myentity:id1” is perfectly fine. It’s the same value as the id element in the ATOM representation.
The uri property is the edit or read link. So it’s the value of the ODataEntry.EditLink or if that’s null it’s the vaue of the ODataEntry.ReadLink. This has to be a valid URL which can be used to read and/or modify the entity.