Here is the Json I am trying to handle with Traverson to extract a single link from this HAL:
{
"_links": {
"curies": [
{
"href": "https://localhost/auth/def/rels/{rel}",
"name": "auth",
"templated": true
}
],
"self": {
"href": "https://localhost/auth/identity"
}
},
"_embedded": {
"auth": [
{
"_links": {
"auth:ad": [
{
"href": "https://localhost/auth/ad"
}
]
},
"kind": "oauth2"
},
{
"_links": {
"auth:default": [
{
"href": "https://localhost/auth/default" // **Link that I need**
}
]
},
"kind": "oauth2"
}
]
}
}
Java code responsible for handling ideally should look like this:
Link test = traverson
.follow("auth")
.follow("$.['_embedded']['auth']..['_links']['auth:default']..['href'][0]")
.asLink();
But for some reason I am getting no hits despite the fact that right before adding the last [0]
in the JSONPath expression I am getting an array of one element. Is there a way to extract this single link so that I am not returned with an array? I used this tool for testing.