@DoNotUseJAXBProvider

Help
2009-09-26
2013-06-06
  • Hi RESTeasy team,

    first I would like to thank you for such a great library. It is a lot of fun to work with it. I have two small issues which I'll post in separate questions. Here is the first one.

    I have a legacy service which needs to emit JSON objects without a type wrapper, e.g.

        {"username":"foo", "password":"bar"}

    instead of

        {"User":{"username":"foo", "password":"bar"}}

    For this I created a **MessageBodyWriter** which does the conversion using the **org.json** library. The content type is **text/plain** (**application/json** has the same issues)

    In order for the RESTEasy library to use my MessageBodyWriter I have to annotate all service methods with **@DoNotUseJAXBProvider** like this which is a bit ugly.

        @GET
        @Path("/user/{userId}")
        @DoNotUseJAXBProvider
        public User getUser(@PathParam("userId") long userId);

    Otherwise I get the following error

        Could not find JAXBContextFinder for media type: text/plain

    Adding the @DoNotUseJAXBProvider to the class is possible but doesn't have any effect.

    Is there a simpler way of telling RESTeasy to use my text/plain MessageBodyWriter all the time?

    Thanks
    Frank

     
  • I am using **RESTeasy 1.1.GA** btw.

    Frank

     
  • I have found a solution for this. This is the communication path

          <- plain JSON (text/plain) ->  <- Jettison JSON (application/json) ->

    As I want to use the same POJO on both the frontend and the backend service annotating the entity classes with **@IgnoreMediaTypes("text/plain")** does the trick.

        @IgnoreMediaTypes("text/plain")
        @XmlRootElement(name = "User")
        public class User {
            private String username;
            private String password;
       
            @XmlElement
            public String getUsername() {
                return username;
            }
       
            public void setUsername(String username) {
                this.username = username;
            }
       
            @XmlElement
            public String getPassword() {
                return password;
            }
       
            public void setPassword(String password) {
                this.password = password;
            }
        }

    Frank