Comments (6)
Due the problems of Jackson Mapping Links like described above I wrote a snippet that loads the links. It looks like this:
ResponseEntity<Object> objRef = restTemplate.getForEntity(url, Object.class);
if (objRef != null && objRef.getStatusCode().compareTo(HttpStatus.OK) == 0) {
ArrayList<HashMap<String, String>> linkMaps = (ArrayList<HashMap<String, String>>) objRef.getBody();
for (HashMap<String, String> linkMap : linkMaps) {
for (Map.Entry<String, String> link : linkMap.entrySet()) {
if (link.getKey().equals("href")) {
response = restTemplate.getForEntity(link.getValue(), clazz);
}
}
object = (T) response.getBody();
}
}
And in my opinion it is awful. Adding the _links back to the result would make it much more comfortable and straight-forward, clean and consistent. Not only for a Java client side as well as for others like Javascript access.
from spring-data-rest.
Sorry I didn't notice this when you posted it. I wasn't getting GitHub notifications of issues for some weird reason.
That code isn't pretty, you're right! :/
I'll put the _links structure back into the search results and build a snapshot with that. If that's easier to work with, then we'll go with that for the next release (wish I'd seen this sooner..I could have gotten it in before I released RC1 :( ).
from spring-data-rest.
Thanks, I will wait for the build and try it again afterwards.
from spring-data-rest.
This isn't as easy as simply adding a _links structure to the response. The problem is that results returned might have to be entities rendered as JSON documents because there is no corresponding Repository exported for them.
This means search results would have to be nested something like this:
{
"results": [
... entities that don't have Repositories exported ...
],
"_links": [
... links ...
]
}
This isn't a problem per se, it's just a departure from the current representation and is a breaking change.
from spring-data-rest.
Jon, yep that's right. For this case I was thinking about the following solution. If I do have a specific search, I am aware of the possible results on the client side. In this case, I could easily create a POJO, inheriting from LinkType (_links(rel,ref)) to get the result.
The question here is, relying on the discussion via e-mail yesterday, if this is necessary at all, because if we stick to your or Olivers suggestion, we would have to types of search results. The first would be a pure list of links to core result objects, while the second would be the core results directly, without the link section before.
from spring-data-rest.
Actually the structure of an object with two properties ("results" and "_links") is necessary in all cases because even when sending back a list of entity results, there are links associated with paging and searches. I still have to have a "_links" section to the response, it's just that it won't have any more links in it than prev/next, search, etc...
The media type is basically a switch to tell the system whether to fill in "result" or "_links". The basic structure of the response at the root level will be the same in any case.
from spring-data-rest.
Related Issues (20)
- Document how to use TestRestTemplate with spring-data-rest
- Release 4.1.10 (2023.0.10)
- Release 4.2.4 (2023.1.4)
- Release 4.3 M2 (2024.0.0)
- Json object not gettting captured in POST request HOT 4
- Upgrade to Spring Security 6.1.7 for integration tests
- Release 4.1.11 (2023.0.11)
- Release 4.2.5 (2023.1.5)
- Release 4.3 RC1 (2024.0.0)
- Upgrade to MongoDB driver 5
- Upgrade to Hibernate 6.5.0.CR1
- Release 4.1.12 (2023.0.12)
- Release 4.2.6 (2023.1.6)
- Release 4.3 GA (2024.0.0)
- [FEATURE REQUEST]: Spring Data JPA Support for Apache Delta Lake HOT 1
- Document error codes for ItemResources HOT 2
- Release 4.2.7 (2023.1.7)
- Release 4.3.1 (2024.0.1)
- Release 4.4 M1 (2024.1.0)
- [Question] Understanding links generated by Spring Data Rest HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-rest.