Quarkus can not change the content-type of the response depending on accept header using reactive routes
See original GitHub issueDescribe the bug
According to the Reactive Route page in Quarkus documentation website, it is possible to send Accept header to set the Content-Type of a response.
I’m sending -H 'Accept: application/xml'
by curl to a Quarkus project with Reactive Routes enabled but I always get the response in JSON format and with Content-Type equals to application/json.
Expected behavior
Quarkus should change the Content-Type format depending on the Accept header.
Actual behavior
Quarkus always returns the response in JSON format with Content-Type: application/json header.
How to Reproduce?
- Create the following class:
package com.serrodcal;
import io.quarkus.vertx.web.Route;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
import java.util.Arrays;
import java.util.List;
@ApplicationScoped
public class PersonResource {
@Route(path = "person", methods = Route.HttpMethod.GET)
public Uni<List<Person>> findAll() {
List<Person> personList = Arrays.asList(new Person("Sergio"), new Person("Pepe"));
return Uni.createFrom().item(personList);
}
public static class Person {
private String name;
public Person(String name) {
this.name = name;
}
public String getName() { return this.name; }
}
}
- Then, send the following curls request:
$ curl http://localhost:8080/person -w '\n' -i
HTTP/1.1 200 OK
Content-Type: application/json
content-length: 35
[{"name":"Sergio"},{"name":"Pepe"}]
$ curl http://localhost:8080/person -w '\n' -i -H 'Accept: application/xml'
HTTP/1.1 200 OK
Content-Type: application/json
content-length: 35
[{"name":"Sergio"},{"name":"Pepe"}]
$ curl http://localhost:8080/person -w '\n' -i -H 'Accept: text/plain'
HTTP/1.1 200 OK
Content-Type: application/json
content-length: 35
[{"name":"Sergio"},{"name":"Pepe"}]
$ curl http://localhost:8080/person -w '\n' -i -H 'Accept: text/html'
HTTP/1.1 200 OK
Content-Type: application/json
content-length: 35
[{"name":"Sergio"},{"name":"Pepe"}]
Output of uname -a
or ver
Darwin MacBook-Pro-de-Sergio-2016.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Output of java -version
openjdk version “11.0.12” 2021-07-20 OpenJDK Runtime Environment GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08) OpenJDK 64-Bit Server VM GraalVM CE 21.2.0 (build 11.0.12+6-jvmci-21.2-b08, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.2.3.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: /Users/serrodcal/.m2/wrapper/dists/apache-maven-3.8.1-bin/2l5mhf2pq2clrde7f7qp1rdt5m/apache-maven-3.8.1 Java version: 11.0.12, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.2.0/Contents/Home Default locale: es_ES, platform encoding: UTF-8 OS name: “mac os x”, version: “11.5”, arch: “x86_64”, family: “mac”
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Reactive routes always encode objects using Jackson.
Ok! I close this issue. Thanks.