相关疑难解决方法(0)

严重:找不到媒体类型= application/json的MessageBodyWriter,type = class com.jersey.jaxb.Todo,genericType = class com.jersey.jaxb.Todo

我正在尝试创建一个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)

java rest json jax-rs jersey

32
推荐指数
3
解决办法
7万
查看次数

严重:找不到媒体类型 = application/xml 的 MessageBodyWriter

我知道这听起来可能像这个或其他一些的重复,但请耐心听我说。

我有一个非常基本的 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)

jax-rs jersey

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

jax-rs ×2

jersey ×2

java ×1

json ×1

rest ×1