skip to Main Content

I’m deploying a REST service written in Java on WebLogic.
The method I’m interested in has this signature:

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("/myway/mock")
public List<String> getMyMock(@QueryParam("pic") String pic, @QueryParam("year") int year)

After I deploy this service to WebLogic I’m calling it from curl or Postman and I see this error in WebLogic logs:

<org.glassfish.jersey.message.internal.WriterInterceptorExecutor> <MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<java.lang.String>.>
Feb 02, 2024 4:09:22 PM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<java.lang.String>.

If I return just a String from this method, it works fine. Only when I try to return List I have this issue. I guess it is due to the fact that WebLogic can’t figure out how to return MediaType.APPLICATION_JSON from List, but there must be a way.

2

Answers


  1. Chosen as BEST ANSWER

    This is what worked for me in the main pom.xml:

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.28</version>
    </dependency>
    

  2. Use Json serializer in the classpath. Try adding this dependency in pom.xml

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.16.1</version>
    </dependency>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search