Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to marshal type "bookmarks.BookmarkResource" #8

Closed
darrylb-github opened this issue Dec 30, 2014 · 6 comments
Closed

Unable to marshal type "bookmarks.BookmarkResource" #8

darrylb-github opened this issue Dec 30, 2014 · 6 comments

Comments

@darrylb-github
Copy link

When running the HATEOAS project as is and browsing to http://localhost:8080/jhoeller/bookmarks I get the following error:

There was an unexpected error (type=Internal Server Error, status=500).
Could not marshal [Resources { content: [links: [<http://bookmark.com/1/jhoeller>;rel="bookmark-uri", <http://localhost:8080/jhoeller/bookmarks>;rel="bookmarks", <http://localhost:8080/jhoeller/bookmarks/1>;rel="self"], links: [<http://bookmark.com/2/jhoeller>;rel="bookmark-uri", <http://localhost:8080/jhoeller/bookmarks>;rel="bookmarks", <http://localhost:8080/jhoeller/bookmarks/2>;rel="self"]], links: [] }]: null; 
nested exception is javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.internal.SAXException2: 
unable to marshal type "bookmarks.BookmarkResource" as an element because it is missing an @XmlRootElement annotation]

Is there something missing here or is it just me?

@darrylb-github
Copy link
Author

This seems to be related to Resources<BookmarkResource> readBookmarks. Changing this to Collection<BookmarkResource> readBookmarks and returning the list without the resources wrapper seems to fix it for me. I'll close this as its probably something to do with my setup.

@ievgen-kapinos
Copy link

Helped for me too. TNX. A lot of typo I've found in this tutorial. So seems it is correct fix.

@ziftytodd
Copy link

For anyone else hitting this error, if you still want to return a true HATEOAS resource (versus a straight-up Collection), change the @RequestMapping on the readBookmarks method to include a produces attribute:

@RequestMapping(method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, "application/hal+json"})

Don't forget to import import org.springframework.http.MediaType;

@jflewis
Copy link

jflewis commented Sep 15, 2017

Is this happening for everyone because I've run into the same issue. Should the above fix by @ziftytodd be implemented? Sorry to bring up a 2 year old issue

@LeonardGC
Copy link

@jflewis I did the tutorial just now and was glad to find this page to solve this issue. The fix of @ziftytodd should be implemented asap.
There are other issues with this tutorial as well, like the pointing to the wrong source code (at the start of the tutorial), the addition of the org.springframework.security.oauth dependency from the beginning, (so the examples don't work but are asking for a username and password), etc...
Very confusing.

@cal0610
Copy link

cal0610 commented Mar 12, 2018

It would also be interesting to see how to test methods readSingleBookmark and readBookmarks after using hateoas links...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants