为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

米脂 2019-12-04 10:31:24
我正在尝试创建一个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)@AutoPropertypublic 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。
查看完整描述

3 回答

?
暮色呼如

TA贡献1853条经验 获得超9个赞

我有同样的问题,我通过在类中添加一个空的构造函数来解决它


public SandBoxClass(){} //-> solved the issue**


public SandBoxClass(Integer arg1, Integer arg2) {

        this.arg1=arg1;

        this.arg2=arg2;

}


查看完整回答
反对 回复 2019-12-04
  • 3 回答
  • 0 关注
  • 464 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信