java - Error while producing XML from REST using Jersey and embedded jetty -


i attempting return simple xml output rest service 500 internal server error , following error in jetty console:

org.glassfish.jersey.message.internal.writerinterceptorexecutor$terminalwriterinterceptor aroundwriteto severe: messagebodywriter not found media type=application/xml, type=class com.example.dbrest.model.saying, generictype=class com.example.dbrest.model.saying. 

i have tried few tricks problem remains. however, if change @produces application_json, works expected:

{"name":"hello jersey!"} 

maven pom.xml has right dependencies jersey, jetty, jackson don't believe specific needed xml? code looks following. missing - perhaps need register in main function? in advance!

model:

package com.example.dbrest.model  @xmlrootelement( name = "saying" ) public class saying  {     public string name;     public saying() {     }      public saying(string name) {         this.name = name;     } } 

resource:

package com.example.dbrest.resources  @path( "/v1/hello" ) public class helloworldresource {     @get     @path( "/{name}" )     @produces( mediatype.application_xml )     public saying getsaying( @pathparam ("name") string name )     {         return new saying("hello " + name + "!");     } } 

main:

public class dbrestlauncher  {     private static final int default_jetty_port = 8888;      public static void main( string[] args )     {         resourceconfig resourceconfig = new resourceconfig();         resourceconfig.packages( "com.example.dbrest.resources" );         resourceconfig.register( jacksonfeature.class );         servletcontainer servletcontainer = new servletcontainer( resourceconfig );         servletholder jerseyservlet = new servletholder( servletcontainer );         servletcontexthandler context = new servletcontexthandler( servletcontexthandler.sessions );         context.setcontextpath("/");         context.addservlet( jerseyservlet, "/api/db/*" );          server jettyserver = new server( default_jetty_port );         jettyserver.sethandler( context );          try         {             jettyserver.start();             jettyserver.join();         }         catch( exception e )         {             e.printstacktrace();         }     } } 


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -