spring-projects / spring-projects/spring-data-rest

Content Negotation to use the registered HttpMessageConverters [DATAREST-1235]

Open
#1,595 10 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: content-negotiation type: enhancement
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Petar Tahchiev opened DATAREST-1235 and commented

Hello,

I want to get the response from Spring Data REST in XML or CSV or some other format. For that reason Spring Data REST allows me to register some extra HttpMessageConverters  in my RepositoryRestConfigurerAdapter like this:

@Override
public void configureHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
  super.configureHttpMessageConverters(messageConverters);

 messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
 messageConverters.add(new MappingJackson2CborHttpMessageConverter());
 messageConverters.add(new MappingJackson2SmileHttpMessageConverter());
 messageConverters.add(new CsvHttpMessageConverter());
}

but seems like they are not used at all.

However even though I specify correct Accept header I get 406 (Not Acceptable).

I found out that RepositoryRestHandlerMapping sets some fallback media types if the RepositoryEntityController has not specified what the methods produce.

If I comment out the 2 lines (just like I have done in this pull request):

https://github.com/spring-projects/spring-data-rest/pull/292/files

then it all seems to work fine - I can get XML/CSV or whatever I specify in the Accept header. Also if I don't specify Accept header I get the JSON back. So i'm not sure what the two lines are for, but to me it seems they are not needed.

 


Affects: 3.0.6 (Kay SR6)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.