簡體   English   中英

jersey.api.MessageException消息正文編寫器和MIME媒體類型text / xml未找到

[英]jersey.api.MessageException message body writer and MIME media type text/xml not found

數據是一個名為“QueryResponse”的對象,后者又擁有一個名為“Todos”的對象列表。

我收到此錯誤:

javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message  body writer for Java class java.util.ArrayList, and Java type java.util.List<de.vogella.jersey.todo.model.Todo>, and MIME media type text/xml was not found

我有這個球衣獲取方法:

@GET
@Produces({"application/xml", "application/json"})
public QueryResponse getTodos() {

 List todos = new ArrayList();
 todos.addAll(TodoDao.instance.getModel().values());
 return  new QueryResponse(todos);
}

這就是QueryResponse對象:

@XmlRootElement

public class QueryResponse {
@XmlElementWrapper(name = "Todos")
@XmlElement(name = "Todo")
private List<Todo> todolist;
public QueryResponse(List<Todo> todolist)
{
    this.todolist = todolist;
}

public void setTodolist(List<Todo> todolist)
{
    this.todolist = todolist;
}
public List<Todo> getTodolist( )
{
    return this.todolist;
}
}

這是Todo課程:

public class Todo
{


  private int id;
  private String summary;
  private String Description;

  public Todo()
 {
 }

  public Todo(int id, String summary)
 {
   this.id = id;
   this.summary = summary;
 }
 public int getId() {
   return this.id;
 }
 public void setId(int userID) {
   this.id = userID;
 }
 public String getSummary() {
   return this.summary;
 }
 public void setSummary(String summary) {
   this.summary = summary;
 }
 public String getDescription() {
   return this.Description;
 }
 public void setDescription(String description) {
    this.Description = description;
 }
}

我感謝您的幫助。

請執行下列操作:

  1. 使用以下注釋注釋public void getTodolist(List<Todo> todolist) :@ @XmlElementRef
  2. 使用以下注釋對QueryResponse進行注釋: @XmlSeeAlso({Todo.class})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM