question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quarkus can not change the content-type of the response depending on accept header using reactive routes

See original GitHub issue

Describe 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?

  1. 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; }

    }

}
  1. 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cescoffiercommented, Oct 11, 2021

Reactive routes always encode objects using Jackson.

0reactions
serrodcalcommented, Oct 11, 2021

Ok! I close this issue. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Reactive Routes - Quarkus
The first way to use reactive routes is to use the @Route annotation. ... acceptable content type by matching the accept header with...
Read more >
Writing REST Services with RESTEasy Reactive - Quarkus
Obtain a resource representation, should not modify state, idempotent (HTTP docs) ... which are indicated by the HTTP Content-Type header, ...
Read more >
HTTP Reference - Quarkus
Additional HTTP Headers per path. If you need different header values depending on the path, you can use the following configuration:.
Read more >
Getting Started With Reactive - Quarkus
This guide will help you with: Bootstrapping a reactive CRUD application with Quarkus. Using Hibernate Reactive with Panache to interact with a database...
Read more >
All configuration options - Quarkus
AWS Lambda Type Default AWS Lambda Common Type Default AWS Lambda Gateway REST API Type Default Agroal ‑ Database connection pool Type Default
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found