Accept header precedence with spring-data-rest

302 views Asked by At

I am trying spring-data-rest with mithril.js. However, I keep getting xml response from the repository instead of json.

I have this repository:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {

And request with this:

var users = m.request({method: "GET", url: "/api/people/"});

However, I just got a list of string in xml response.

I tried to check the source as below, though I may mislook and point out the wrong source:

Found that mithril set the accept header as

xhr.setRequestHeader("Accept", "application/json, text/*")

mithril source: line 1079

However, it sounds spring-data-rest handle the request with

@ResponseBody
@SuppressWarnings({ "unchecked" })
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, produces = {
        "application/x-spring-data-compact+json", "text/uri-list" })
public Resources<?> getCollectionResourceCompact(RootResourceInformation repoRequest, DefaultedPageable pageable,

spring-data-rest source: line 171-173

instead of

@ResponseBody
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET)
public Resources<?> getCollectionResource(final RootResourceInformation resourceInformation,

on spring-data-rest source: line 210-213

Is anything wrong on my ajax request?

1

There are 1 answers

2
cgrinds On

Use curl to create the request and get that working the way you think it should. After that works, tackle the mithril part.