【发布时间】:2016-04-25 17:36:52
【问题描述】:
我正在尝试用球衣制作一个示例 REST 服务器。我能够重新运行一个简单的字符串,但是当我尝试返回一个数组时,我得到了这个错误
A message body writer for Java class [C, and Java type class [C, and MIME media type application/json was not found.
我也尝试添加@XMLRootElement,但问题仍然存在。这是我的代码:
@Path("/test")
public class Test {
@GET
@Produces( MediaType.APPLICATION_JSON )
public char[] getHello() {
char[] test = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
'i', 'n', 'a', 't', 'e', 'd' };
return test;
}
}
编辑:添加了 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>HospitalServer</groupId>
<artifactId>HospitalServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
请出示您的
pom.xml。 -
帖子已编辑,添加了 pom.xml
-
只是好奇,您为什么要使用最新的 Java 版本和最古老的 Jersey 版本之一?
-
我在关注不同的教程,也许其中一个使用了旧版本的球衣。你认为这会导致之后的问题吗?