jersey.api.MessageException message body writer and MIME media type text/xml not found
11,196
Do the following:
-
Annotate
public void getTodolist(List<Todo> todolist)
with the following annotation:@XmlElementRef
- Annotate your QueryResponse with the following annotation:
@XmlSeeAlso({Todo.class})
Related videos on Youtube
Author by
Marwan Tushyeh
Updated on September 15, 2022Comments
-
Marwan Tushyeh over 1 year
The data is an object named "QueryResponse" which in turn owns a list of objects called "Todos".
I get this error:
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
I have this jersey get method:
@GET @Produces({"application/xml", "application/json"}) public QueryResponse getTodos() { List todos = new ArrayList(); todos.addAll(TodoDao.instance.getModel().values()); return new QueryResponse(todos); }
And that's the QueryResponse object:
@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; } }
And this is the Todo class:
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; } }
I appreciate your help.
-
Amir Kost about 11 yearsAnnotate the Todo class with JAXB annotations.
-
Marwan Tushyeh about 11 yearsi'm not sure what annotations should be present in the TODO, can you help me with that?
-
Amir Kost about 11 yearsXmlRootElement And remove the annotations you have from the XmlElement todolist member. (except for XmlElementRef)