[[object-collection]]
= Domain Object Collection

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



If a domain object collection (link:https://www.restfulobjects.org/spec/1.0/section-c/chapter-17.html[section 17]) is accessed with this profile, then the resultant representation is as an array of elements of key/value for each referenced object, and again each element the containing the key/value pairs of the properties of that object (a grid, again).

In addition, the representation defined by the RO spec is also included, as a special object with a single `$$ro`
property.

For example, in a todo app, accessing this resource:

[source]
----
http://localhost:8080/restful/objects/TODO/45/collections/similarTo
----

with an `Accept` request header of:

[source]
----
Accept: application/json;profile="urn:org.apache.causeway/v2"
----

returns the following representation:

[source]
----
[                                                                   // <1>
{
  "$$href" : "http://localhost:8080/restful/objects/TODO/46",       // <2>
  "$$instanceId" : "46",                                            // <3>
  "$$title" : "Buy milk due by 2015-12-04",                         // <4>
  "description" : "Buy milk",                                       // <5>
  "category" : "Domestic",
  ...
}, {
  "$$href" : "http://localhost:8080/restful/objects/TODO/47",
  "$$title" : "Buy stamps due by 2015-12-04",
  "description" : "Buy stamps",
  "category" : "Domestic",
  ...
}, {
  "$$href" : "http://localhost:8080/restful/objects/TODO/48",
  "$$title" : "Mow lawn due by 2015-12-10",
  "description" : "Mow lawn",
  "category" : "Domestic",
  ...
},
...
, {
  "$$ro" : {                                                        // <6>
    "id" : "similarTo",
    "memberType" : "collection",
    "links" : [ ... ],
    "extensions" : { /* ... */ },
    "value" : [ ... ]
  }
}
]
----
<1> returns a JSON array, not a JSON object
<2> hyperlink to the representation
<3> instance id of the domain object (unique within its type)
<4> title of the domain object
<5> all the properties of the domain object (to which the caller has access), as key/value pairs
<6> last element is a special object with a single `$$ro` json-prop, being the normal RO Spec representation for this object

with a `Content-Type` header:

[source]
----
Content-Type: application/json;profile="urn:org.apache.causeway/v2";repr-type="object-collection"
----


