【发布时间】:2023-03-10 07:31:01
【问题描述】:
我最初编写了一个 java 应用程序(命令行应用程序),现在我试图将其转换为使用 jersey 和 jetty 嵌入的 Web 应用程序。现在作为服务休息类的输出,我需要以 json 格式输出List<List<Map<String,String>>>。有没有办法做到这一点?我是 servlet 和东西世界的新手.. 我试过这样:
@得到
@Path("测试")
@Produces(MediaType.APPLICATION_JSON)
public List>> test() throws FileNotFoundException, IOException, GateException, URISyntaxException {
System.out.println("Starting the App");
System.out.println("Locations added successfully");
DataFile file = new CSVDataFile();
CommandsExecutor.outputsList.add(0, file.performReadOperation(inputFilePath));
System.out.println("Begining execution");
List<List<Map<String, String>>> finalOutput = CommandsExecutor.executeSequentialCommands(file);
/* for (List<Map<String, String>> tmpList : finalOutput) {
for (int i = 0; i < tmpList.size(); i++) {
Map<String, String> insideMap = tmpList.get(i);
// for (Map.Entry<String, String> entry : insideMap.entrySet())
// {
// System.out.println(entry.getKey() + "/" + entry.getValue());
// }
JSONObject obj = new JSONObject(insideMap);
System.out.println(obj);
}
System.out.println("\n");
} */
return finalOutput;
}
现在我收到这样的错误:无法发送响应错误 500: javax.servlet.ServletException: org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List>>.
可以解决什么问题?提前致谢!!
【问题讨论】:
-
我了解到,如果你正在编写一些难以理解的代码 (List
- >>)
标签: java json rest jersey-2.0