Git Product home page Git Product logo

Comments (6)

jhiemer avatar jhiemer commented on July 19, 2024

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.

jbrisbin avatar jbrisbin commented on July 19, 2024

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.

jhiemer avatar jhiemer commented on July 19, 2024

Thanks, I will wait for the build and try it again afterwards.

from spring-data-rest.

jbrisbin avatar jbrisbin commented on July 19, 2024

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.

jhiemer avatar jhiemer commented on July 19, 2024

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.

jbrisbin avatar jbrisbin commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.