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

RESTEasy reactive passed null media type for MessageBodyWriters #25263

Closed
sithmein opened this issue Apr 29, 2022 · 4 comments · Fixed by #25291
Closed

RESTEasy reactive passed null media type for MessageBodyWriters #25263

sithmein opened this issue Apr 29, 2022 · 4 comments · Fixed by #25291
Assignees
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@sithmein
Copy link

sithmein commented Apr 29, 2022

Describe the bug

Consider the following JAX-RS resource class and MessageBodyWriter:

@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public class MediaTypeLost {
	@Provider
	@Produces(MediaType.APPLICATION_JSON)
	public static class GenericJSONSerializer implements MessageBodyWriter<Object> {
	    @Override
	    public long getSize(final Object value, final Class<?> type, final Type genericType,
	        final Annotation [] annotations, final MediaType mediaType) {
	        return -1;
	    }

	    @Override
	    public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation [] annotations,
	        final MediaType mediaType) {
	        return true;
	    }

	    @Override
	    public void writeTo(final Object value, final Class<?> type, final Type genericType,
	        final Annotation[] annotations, final MediaType mediaType,
	        final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
	        throws IOException {
	        
	    	Objects.requireNonNull(mediaType);
	    }
	}

	
    @GET
    @Path("foo")
	public Response doSomething() {
    	var map = Map.of("key", "value");
	    return Response.ok(map).build();
	}
}

Invoking the resource method with quarkus-resteasy-reactive will result in an exception because the mediaType parameter passed into the message body writer is null. This works without problems in the non-reactive version and any other JAX-RS framework that I have used in the past.
It works if the Response explicitly defines its media type it works, but according to section 3.8 of the JAX-RS specification this is not necessary and the media type can be derived from @Produces annotations.

Expected behavior

The message body writer should receive the correct media type (application/json in this case), according to the JAX-RS specification.

Actual behavior

The media type is null.

How to Reproduce?

Run the provided example with reactive RESTEasy.

Output of uname -a or ver

No response

Output of java -version

17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.8.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@sithmein sithmein added the kind/bug Something isn't working label Apr 29, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 29, 2022

/cc @FroMage, @geoand, @stuartwdouglas

@geoand
Copy link
Contributor

geoand commented Apr 30, 2022

Thanks for reporting.

Do you mind attaching a sample project that exhibits this behavior?

@sithmein
Copy link
Author

You can find reproducers/tests for this issue at https://github.com/sithmein/bugs-in-quarkus

@geoand geoand self-assigned this May 2, 2022
geoand added a commit to geoand/quarkus that referenced this issue May 2, 2022
@geoand
Copy link
Contributor

geoand commented May 2, 2022

I'm surprised that none of the TCK tests actually tested this...

In any case, #25291 fixes the null media type issue.
Please open a new issue if there is another problem (as indicated by the other test in your repo)

geoand added a commit that referenced this issue May 3, 2022
Properly pass media type to MessageBodyWriters
@quarkus-bot quarkus-bot bot added this to the 2.10 - main milestone May 3, 2022
@gsmet gsmet modified the milestones: 2.10 - main, 2.9.0.Final May 3, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 3, 2022
@gsmet gsmet modified the milestones: 2.9.0.Final, 2.8.3.Final May 5, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 5, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 5, 2022
@gsmet gsmet modified the milestones: 2.8.3.Final, 2.7.6.Final May 18, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants