Tomcat 9 - application/json was not found

Asked

Viewed 74 times

1

Greetings,

I am developing a WS in Jersey/Restful which is working properly in Glassfish but in Tomcat I get the error when trying to consume the service.

GRAVE: Mapped Exception to Answer: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class java.util.ArrayList, and Java type java.util.ArrayList, and MIME media type application/json was not found at com.sun.jersey.spi.container.ContainerResponse.write(Containerresponse.java:285) at com.sun.jersey.server.impl.application.Webapplicationimpl. _handleRequest(Webapplicationimpl.java:1437)

Only occurs with produces "application/json" or Mediatype.APPLICATION_JSON already with "text/html" does not give error in Tomcat.

someone has been there?!

[]s

  • Could post your code and configuration file?

  • I’m sorry, I hadn’t noticed your comment... but I’ve discovered the problem... see below... Thank you !

1 answer

0

Good. By converting Arraylist to String with Gson I was able to succeed, but I was intrigued and researching found that only by including Genson in the project my problem would be solved ... and it was!.

The explanation...

We need to tell Jersey that the java class should be converted to Json by checking specifications like Setter / getter classes, whether present or not.

    <dependency>
        <groupId>com.owlike</groupId>
        <artifactId>genson</artifactId>
        <version>1.3</version>
    </dependency> 

What I don’t understand is why it only takes Tomcat since Glassfish ran without error... but it’s for another search...

[]s

source :https://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/ (questions and answers on the subject)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.