MessageBodyWriter não encontrado para o tipo de mídia = application / json
Estou fazendo um pequeno serviço RESTful usando o Jetty. Usando o Maven como a ferramenta de construção.
Quando tento chamar um método GET que tenta acessar uma representação JSON de um objeto, recebo o erro "MessageBodyWriter". O método em questão é o seguinte,
@Path("/gtfs-rt-feed")
public class GtfsRtFeed {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getGtfsRtFeed(){
GtfsRtFeedModel feedInfo = new GtfsRtFeedModel();
feedInfo.setStartTime(121334);
feedInfo.setGtfsId(1);
feedInfo.setGtfsUrl("http://www.google.com");
Gson gson = new Gson();
return Response.ok(feedInfo).build();
}
...
O GtfsRtFeedModel para o GtfsRtFeedModel é o seguinte,
@XmlRootElement
public class GtfsRtFeedModel {
private String gtfsUrl;
private int gtfsId;
private long startTime;
public GtfsRtFeedModel(){}
public String getGtfsUrl() {
return gtfsUrl;
}
...//Getters and setters for all private variables below
O arquivo My Maven inclui o seguinte, juntamente com as dependências do jetty,
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.19</version>
</dependency>
A maioria das perguntas semelhantes parece ter sido resolvida adicionandojersey-media-moxy
e as dependências necessárias. Mas como já os tenho no meu arquivo de maquilhagem, não consigo descobrir o que estou perdendo.
Qualquer ajuda seria apreciada.
EDIT: Jetty code added Meu código do Jetty é o seguinte,
public static void main(String[] args) throws Exception{
GTFSDB.InitializeDB();
Datasource ds = Datasource.getInstance();
ds.getConnection();
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.setResourceBase(BASE_RESOURCE);
server.setHandler(context);
context.addServlet(RTFeedValidatorServlet.class, "/validate");
context.addServlet(GTFSDownloaderServlet.class, "/downloadgtfs");
context.addServlet(FeedInfoServlet.class, "/feedInfo");
context.addServlet(TriggerBackgroundServlet.class, "/startBackground");
context.addServlet(GetFeedJSON.class, "/getFeed");
context.addServlet(DefaultServlet.class, "/");
ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/api/*");
jerseyServlet.setInitOrder(1);
jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "edu.usf.cutr.gtfsrtvalidator.api.resource");
server.start();
server.join();
}