调用返回部署在 WebLogic 中的 List<String> 的 REST 服务时出现运行时错误

问题描述 投票:0回答:1

我正在 WebLogic 上部署用 Java 编写的 REST 服务。 我感兴趣的方法有这个签名:

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

将此服务部署到 WebLogic 后,我从curl 或 Postman 调用它,并在 WebLogic 日志中看到此错误:

type=class java.util.ArrayList, genericType=java.util.List.> 2024 年 2 月 2 日下午 4:09:22 org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo 严重:找不到 Media type=application/json、type=class java.util.ArrayList、genericType=java.util.List.

的 MessageBodyWriter

如果我从此方法中仅返回一个字符串,则它可以正常工作。仅当我尝试返回列表时,我才会遇到此问题。我猜这是因为WebLogic无法弄清楚如何从List返回MediaType.APPLICATION_JSON,但一定有办法。

java json weblogic
1个回答
0
投票

在类路径中使用 Json 序列化器。尝试在 pom.xml 中添加此依赖项

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.16.1</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.