严重:找不到媒体类型= application / json,类型

我正在尝试创建一个RESTful Web服务,并且创建了一个,但是我得到了一个


找不到针对Media type = 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 boolean equals(Object o) {

        return Pojomatic.equals(this, o);

    }


    @Override

    public int hashCode() {

        return Pojomatic.hashCode(this);

    }


    @Override

    public String toString() {

        return Pojomatic.toString(this);

    }


    public static class Builder {

        private String description;

        private String summary;


        public Builder summary(String summary) {

            this.summary = summary;

            return this;

        }


        public Builder description(String description) {

            this.description = description;

            return this;

        }


        public Todo build() {

            return new Todo(this);

        }

    }

}

当我在Tomcat服务器上运行此应用程序并运行它时: http:// localhost:8080 / MyFirstWebService / rest / todo


我得到了错误:


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


米脂
浏览 490回答 3
3回答

暮色呼如

我有同样的问题,我通过在类中添加一个空的构造函数来解决它public SandBoxClass(){} //-> solved the issue**public SandBoxClass(Integer arg1, Integer arg2) {        this.arg1=arg1;        this.arg2=arg2;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java