Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Produces({MediaType.APPLICATION_XML}) error #10

Closed
yale8848 opened this issue Jan 30, 2018 · 2 comments
Closed

@Produces({MediaType.APPLICATION_XML}) error #10

yale8848 opened this issue Jan 30, 2018 · 2 comments

Comments

@yale8848
Copy link

    @GET
    @Path("/h1")
    @Produces({MediaType.APPLICATION_XML})
    public Response h1(){
        User u = new User();
        u.setPassword("p");
        u.setName("a");
        return Response.ok(u).build();
    }

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

Why this happen?

@drejc
Copy link
Member

drejc commented Jan 30, 2018

OK ... I have not enough information to debug this ...

  • do you have a writer associated with this media type? ... XML by default has no associated writer
  • do you have a Response implementation associated ?
  • can the User object be deserialized ... ?

For instance ... create a XmlWriter ...

public class MyXmlWriter implements HttpResponseWriter<User> {

	@Override
	public void write(User result, HttpServerRequest request, HttpServerResponse response) {

		response.end("<u name=\"" + result.name  + "\" />");
	}
}

Associate the writer with your mime type ... method
RestRouter.getWriters().register(MediaType.APPLICATION_XML_TYPE, MyXmlWriter.class);

or
RestRouter.getWriters().register(User.class, MyXmlWriter.class);

or

@GET
@Path("/h1")
@Produces({MediaType.APPLICATION_XML})
@ResponseWriter(MyXmlWriter.class)
public Response h1() {
	User u = new User("test");
	return Response.ok(u).build();
}

@yale8848
Copy link
Author

It can work. Thank you very much. 👍

drejc added a commit that referenced this issue Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants