[[domain-object]]
= Domain Object

: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.


:dollar: $

If a domain object resource (link:https://www.restfulobjects.org/spec/1.0/section-c/chapter-14.html[section 14]) is accessed with the Apache Isis profile, the resultant representation is a JSON object with simple key/value pairs for each property.

The contents of any collections are also eagerly returned, consisting of an array of elements of each referenced object.
Each such element contains key/value pairs of each property (in other words, a grid of data is returned).
Each element also has a special `{dollar}{dollar}href` property (so that the client can easily navigate to a resource for that object) and a `{dollar}{dollar}title` property (to use as a label, eg the hyperlink text).

In addition, the representation defined by the RO spec is also included, under a special `{dollar}{dollar}ro` property.

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

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

with an `Accept` request header of:

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

returns the following representation:

[source]
----
{
  "$$href" : "http://localhost:8080/restful/objects/TODO/45",       // <1>
  "$$instanceId" : "45",                                            // <2>
  "$$title" : "Buy bread due by 2015-12-04",                        // <3>
  "description" : "Buy bread",                                      // <4>
  "category" : "Domestic",
  "subcategory" : "Shopping",
  "complete" : false,
  "atPath" : "/users/sven",
  ...
  "similarTo" : [ {                                                 // <5>
    "$$href" : "http://localhost:8080/restful/objects/TODO/46",
    "$$instanceId" : "46",
    "$$title" : "Buy milk due by 2015-12-04",
    "description" : "Buy milk",
    "category" : "Domestic",
    ...
  }, {
    "$$href" : "http://localhost:8080/restful/objects/TODO/47",
    "$$instanceId" : "47",
    "$$title" : "Buy stamps due by 2015-12-04",
    "description" : "Buy stamps",
    "category" : "Domestic",
    ...
  },
     ...
  } ],
  "dependencies" : [ ],
  "$$ro" : {                                                        // <6>
    "links" : [ ... ],
    "extensions" : { /* ... */ },
    "title" : "Buy bread due by 2015-12-04",
    "domainType" : "TODO",
    "instanceId" : "45",
    "members" : { /* ... */ }
  }
}
----
<1> hyperlink to the representation
<2> instance id of the domain object (unique within its type)
<3> title of the domain object
<4> all the properties of the domain object (to which the caller has access), as key/value pairs
<5> contents of each collection
<6> special `$$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.isis/v2";repr-type="object"
----


