You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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"
}
}
}
]
}
}
The text was updated successfully, but these errors were encountered: