Could not find JAXBContextFinder for media type: a

2019-06-08 04:35发布

问题:

I have a problem with development resteay+ejb+json. Using Jboss-5.1.0.GA. I get example from resteasy-jaxrs and adapted to use for my case. Added jars(this ask me jboss. in other case catch exception - class not found) into \jboss-5.1.0.GA\server\default\lib\

resteasy-jaxb-provider-1.2.1.GA jaxrs-api-2.0.1.GA resteasy-jaxrs-2.0.1.GA

Get exception

    09:43:15,502 ERROR [SynchronousDispatcher:error] Failed executing GET /basic
    org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException: Could not find JAXBContextFinder for media type: application/json    
   at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:50)
    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:127)
    at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:103)

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>2.0.0.GA</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>1.1.GA</version>
</dependency>

@Stateless
public class SimpleResourceBean implements SimpleResource {

    @Override
    public Book getBasic() {
        System.out.println("getBasic()");
        return new Book("AAA", "CCC", "SSSS");
    }  
}

@Path("/")
public interface SimpleResource {

    @GET
    @Path("basic")
   // @Produces("text/plain")
    @Produces("application/json")
    Book getBasic();

}

@BadgerFish
@XmlRootElement(name = "book")
public class Book
{   
   private String author;
   private String ISBN;
   private String title;

   public Book()
   {
   }

   public Book(String author, String ISBN, String title)
   {
      this.author = author;
      this.ISBN = ISBN;
      this.title = title;
   }

   @XmlElement
   public String getAuthor()
   {
      return author;
   }

   public void setAuthor(String author)
   {
      this.author = author;
   }

   @XmlElement
   public String getISBN()
   {
      return ISBN;
   }

   public void setISBN(String ISBN)
   {
      this.ISBN = ISBN;
   }

   @XmlAttribute
   public String getTitle()
   {
      return title;
   }

   public void setTitle(String title)
   {
      this.title = title;
   }
}

Please, any suggestion. Best regards Artem

回答1:

RestEasy no longer includes JSON support in the JARs. http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html_single/index.html#JAXB_+_JSON_provider

You need to go get a JAX-B JSON library from http://jettison.codehaus.org/



回答2:

Please try including @DoNotUseJAXBProvider for the method that you are getting the error for. This worked for me. But this was for text/html This is mentioned in http://docs.jboss.com/seam/3/rest/snapshot/reference/en-US/html_single/



回答3:

http://jettison.codehaus.org/ not work for me because the .jar in this website not work with resteasy.

You must download resteasy-jettison-provider.jar because this jar implement jettison for resteasy (work for me) : http://www.java2s.com/Code/Jar/r/Downloadresteasyjettisonproviderjar.htm



回答4:

I used jackson provider

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.0.1.GA</version>
    </dependency>

and solved problem.

note that resteasy-jackson-provider depends on resteasy-jettison-provider



回答5:

adding the following jar resolved my issue:

<dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jettison-provider</artifactId>
        <version>2.2.0.GA</version>
</dependency>