I am using Spring Framework 4.1.0 and Spring HATEOAS 0.16.0 to develop both a Spring web application and a Spring test client for that application.
The test client has a statement like:
ResponseEntity<Resource<Calculation>> response = restTemplate.exchange(
calculationsUri,
HttpMethod.POST,
new HttpEntity<Calculation>(calculation),
new ParameterizedTypeReference<Resource<Calculation>>()
);
...wherein Calculation
is a POJO with Jackson annotations (for example, @JsonProperty
).
Without CURIEs, that RestTemplate.exchange()
invocation succeeds: response.getBody().getLinks()
returns a non-null non-empty instance of List<Link>
.
My web application has non-standard link relations, for example, "sub-calculations". I want to use CURIEs.
With CURIEs, that RestTemplate.exchange()
invocation fails: The response-deserialization code throws org.springframework.http.converter.HttpMessageNotReadableException
, caused by com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException
:
'Could not read JSON: Unrecognized field "name" (class org.springframework.hateoas.Link), not marked as ignorable (one known property "href"])'
In particular, Jackson fails to deserialize the CURIE(s) from the _links
map in the response JSON to the List<Link>
-typed field org.springframework.hateoas.ResourceSupport.links
. The response JSON looks like:
{
"_links" : {
"self" : {
"href" : "..."
},
"myNamespace:sub-calculations" : [ {
"href" : "..."
}, {
"href" : "..."
} ],
"curies" : [ {
"href" : ".../{rel}",
"name" : "myNamespace",
"templated" : true
} ]
}
}
How may I use RestTemplate.exchange()
to obtain a resource whose HAL+JSON ("application/hal+json") representation uses CURIEs?