JAXB MessageBodyReader providers not recognized when using generics in a complex inheritance structure in JBoss EAP 6

Solution Verified - Updated -

Issue

At the scenario given below, RESTeasy is not able to find the correct MessageBodyReader for an incoming XML HTTP Body. I have the abstract resource:

public class AbstractResource<T> {

    @POST
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response createEntity(T entity) {
        return Response.ok("Success!").build();
    }

}

Then an intermediary class:

public class OtherAbstractResource<T> extends AbstractResource<T>{}

And two resources test(doesn't work) and test2(will work in any scenario):

@Path("test2")
@Stateless
public class ConcreteClassThatWorks extends AbstractResource<Model>{

}

@Stateless
@Path("/test")
public class ConcreteResource extends OtherAbstractResource<Model> {

}

I deploy my application and test both resources for XML, see:

[wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '<model></model>' -H 'content-type: application/xml' http://localhost:8080/generics-resteasy/test
<html><head><title>JBoss Web/7.2.2.Final-redhat-1 - JBWEB000064: Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>JBWEB000065: HTTP Status 400 - Could not find message body reader for type: T of content type: application/xml</h1><HR size="1" noshade="noshade"><p><b>JBWEB000309: type</b> JBWEB000067: Status report</p><p><b>JBWEB000068: message</b> <u>Could not find message body reader for type: T of content type: application/xml</u></p><p><b>JBWEB000069: description</b> <u>JBWEB000120: The request sent by the client was syntactically incorrect.</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.2.2.Final-redhat-1</h3></body></html>


[wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '<model></model>' -H 'content-type: application/xml' http://localhost:8080/generics-resteasy/test2
Success!

Both will work for JSON:

[wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '{}' -H 'content-type: application/json' http://localhost:8080/generics-resteasy/test2
Success!

[wsiqueir@wsiqueir secured-servlet]$ curl -X POST --data '{}' -H 'content-type: application/json' http://localhost:8080/generics-resteasy/test
Success!

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.0.x
    • 6.1.x
    • 6.2.x
    • 6.3.1
    • 6.3.2

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.