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
This is what worked for me in the main pom.xml:
Use Json serializer in the classpath. Try adding this dependency in pom.xml