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

JSON Jackson does not handle resource returning CompletionStage<X> #3672 #3978

Open
wants to merge 4 commits into
base: 2.x
Choose a base branch
from

Conversation

mageshwaranr
Copy link

A resource method like below fails with java.lang.IllegalArgumentException: Class * not subtype of *.

@GET
@Produces({"application/json" })
@Path("async")
public CompletionStage<Hello> asyncHello(@NotNull @PathParam(value = "lang") String lang,
                                         @NotNull @Size(min = 2) @QueryParam("yo") String greet){
        return CompletableFuture.supplyAsync(() -> new Hello(lang, greet);
}

This pull request attempts to fix this. Let me know whether the fix is appropriate.

@jansupol
Copy link
Contributor

#3672

…d its sub-classes

Signed-off-by: mageshwaranr <mageshwaran.r@gmail.com>
…d its sub-classes

Signed-off-by: mageshwaranr <mageshwaran.r@gmail.com>
@jansupol
Copy link
Contributor

jansupol commented Nov 2, 2018

There is a valid ECA on file for mageshwaran.r@gmail.com.

Copy link
Contributor

@jansupol jansupol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, it looks good. However, any PR that modifies the code should have a test. Jackson seems to have tests under examples/json-jackson.

@mageshwaranr
Copy link
Author

Sorry for the delay. Added test cases. Is there a way to re-trigger build ?
Not sure whether test is failing due to code issue.

@mageshwaranr mageshwaranr changed the title JSON Jackson does not handle resource returning CompletionStage<X> #3672 JSON Jackson does not handle resource returning CompletionStage<X> #3672 Dec 14, 2018
@mageshwaranr
Copy link
Author

Attempting to re-trigger the build

@mageshwaranr
Copy link
Author

@jansupol Anything expected from me to take this forward ?

Copy link
Author

@mageshwaranr mageshwaranr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added required test cases

@dandew
Copy link

dandew commented Mar 13, 2019

@jansupol Can we please have this in 2.29? This has been hurting for a while now 😅

@jansupol
Copy link
Contributor

jansupol commented Mar 19, 2019

Hm,...I was about to approve this...but then I realized (late, sorry)...

org/glassfish/jersey/jackson/internal/jackson/jaxrs/base/ProviderBase.java is actually repackaged from Jackson 2.8.10.

Should the PR be made against Jackson rather than against Jersey? If a new version gets repackaged, the code could be lost...The best way is to create a PR against Jackson (2.9.x) and then a PR/issue to Jersey to repackage the latest version

Sorry for that coming late, but it still is doable before 2.29.

@jansupol
Copy link
Contributor

Hm... If it gets merged to Jackson, we can merge this to Jersey, too. But since this is 3rd party code, we need to ask for a CQ, first.

@jansupol
Copy link
Contributor

The last commit is missing sign-off-by (-s)...

@@ -0,0 +1,44 @@
package org.glassfish.jersey.examples.jackson;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header is missing

@jansupol
Copy link
Contributor

jansupol commented Jun 5, 2019

@mageshwaranr The code in Jackson seems to be stable at least from 2.8.4. I think we could add this to Jersey. Can you please fix the reported issues?

  • copyright header in the example resource class
  • add sign off
  • please force push so that git hub check does not see the commit with the missing sign-off

@jansupol
Copy link
Contributor

We have adopted Jackson 2.9.9

@edinardo
Copy link

@mageshwaranr could you please add the last request from @jansupol so we can have it.
So far, this is the only impediment to use JAX-RS 2.1 async standard with the official build.

@jpadre
Copy link

jpadre commented Apr 13, 2020

@mageshwaranr could you please add the last request from @jansupol so we can have it.
So far, this is the only impediment to use JAX-RS 2.1 async standard with the official build.

There's one more thing missing to complete this for me, which is to unwrap CompletionException properly so appropriate javax.ws.rs.ext.ExceptionMapper are called down the line.

If it helps anyone else, I am modifying the mapException method of org.glassfish.jersey.server.ServerRuntime using this code to workaround it, but unsure if there's a better way it can be integrated:

private Response mapException(final Throwable originalThrowable) throws Throwable {
	LOGGER.log(Level.FINER, LocalizationMessages.EXCEPTION_MAPPING_START(), originalThrowable);
	Throwable throwable = originalThrowable;
	boolean inMappable = false;
	boolean mappingNotFound = false;

	do {
		//---------------------------------- Begin Change -----------------------------------
		if (throwable instanceof CompletionException && throwable.getCause() != null) {
			throwable = throwable.getCause();
		}
		//----------------------------------- End Change ------------------------------------   
		if (throwable instanceof MappableException)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants