Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link layout does not reflect data if array of one item #118

Closed
tfrigge opened this issue Jan 15, 2016 · 2 comments
Closed

Link layout does not reflect data if array of one item #118

tfrigge opened this issue Jan 15, 2016 · 2 comments

Comments

@tfrigge
Copy link

tfrigge commented Jan 15, 2016

If you have List of data with one element in it it will serialize as an array in JSON with one item, but the link will be just a single item not in an array. If the array of items has more than one item, it will serialize both as an array. This could pose a problem to people who are trying to programatically access the links section, as the data type can change for essentially the same data. I've posted an example JSON below which will happen if you take the sample beer code provided and remove all but one beer for a brewery.

See the _links section, beer link. This is typically an array if there is more than one beer. In the embedded section, the beer is in an array.

{
"TotalResults": 1,
"TotalPages": 1,
"Page": 1,
"_links": {
"self": {
"href": "/breweries/1/beers?page=1"
},
"page": [
{
"href": "/breweries/{id}/beers{?page}",
"templated": true
},
{
"href": "/beers{?searchTerm,page}",
"templated": true
}
],
"beer": {
"href": "/beers/3"
}
},
"_embedded": {
"beer": [
{
"Id": 3,
"Name": "Day Of The Long Shadow",
"BreweryId": 1,
"BreweryName": "Little Creatures",
"StyleId": 3,
"StyleName": "Winter Warmer",
"_links": {
"self": {
"href": "/beers/3"
},
"style": {
"href": "/styles/3"
},
"brewery": {
"href": "/breweries/1"
}
}
}
]
}
}

@kbrichan
Copy link
Collaborator

The output conforms to the HAL spec (https://tools.ietf.org/html/draft-kelly-json-hal-06#section-4.1.1) where it defines "_link": It is an object whose property names are link relation types (as
defined by [RFC5988]) and values are either a Link Object or an array
of Link Objects.

@panmanphil
Copy link
Collaborator

closing stale issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants