我正在尝试创建一个RESTful Web服务,我创建了一个,但我得到了一个
找不到媒体类型= application/json错误的MessageBodyWriter
我的Todo班级:
package com.jersey.jaxb;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.pojomatic.Pojomatic;
import org.pojomatic.annotations.AutoProperty;
@XmlRootElement
@XmlType(name = "todo")
@XmlAccessorType(XmlAccessType.FIELD)
@AutoProperty
public class Todo {
@XmlElement(name = "summary")
private final String summary;
@XmlElement(name = "description")
private final String description;
public String getSummary() {
return summary;
}
public String getDescription() {
return description;
}
public Todo() {
this(new Builder());
}
public Todo(Builder builder) {
this.summary = builder.summary;
this.description = builder.description;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我知道这听起来可能像这个或其他一些的重复,但请耐心听我说。
我有一个非常基本的 JAX-RS 资源,添加了我在本教程中看到的所有必需注释,我在此处遵循。
但我不断HTTP Status 500在 Eclipse 控制台中收到以下日志输出。
Mar 18, 2021 1:35:23 AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.varun.demorest.model.User, genericType=class com.varun.demorest.model.User.
Run Code Online (Sandbox Code Playgroud)
使用 Maven,但即使在添加了我在类似问题上找到的大多数建议后,我发现它大部分已经包含在
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
Run Code Online (Sandbox Code Playgroud)
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.varun</groupId>
<artifactId>demorest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>demorest</name>
<build>
<finalName>demorest</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use …Run Code Online (Sandbox Code Playgroud)