Properly return org.w3c.dom.Document as JSON using Jersey
问题 I have a function which returns type org.w3c.dom.Document, and my Jersey resource lets it return either as XML or JSON. It returns the XML fine, however, for JSON, it returns a simple string, which is just the XML using Application/JSON. How can I make it encode to JSON properly? I'm open to changing the return type of the function to something that can properly be serialized by Jersey 回答1: You would have to write your own MessageBodyWriter for application/json media type and org.w3c.dom