Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:13:04+00:00 2026-06-15T13:13:04+00:00

I am trying to create a rest api server on top of my quartz

  • 0

I am trying to create a rest api server on top of my quartz scheduler. I want to be able to return the org.quartz.Trigger and org.quartz.JobDetail objects as JSON. The problem is that I cannot add the @XmlRootElement to these classes without having to recompile the jar and this causes problems with future upgrades etc. I have tested and am able to serialize a list of classes when adding the @XmlRootElement but when I try to return a List I get the error “A message body writer for Java class java.util.ArrayList, and Java type java.util.List, and MIME media type application/json was not found”. I have tried adding a custom MessageBodyWriter but that does not seem to fix the problem either. Is there a way to marshal the quartz classes to JSON without having to modify the quartz code to add the @XmlRootElement. I am using this in an embedded web server with jetty btw.

@Path("/jobs")
public class JobsResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Trigger> listScheduledJobs() throws SchedulerException {
        return TaskEngine.getInstance().listScheduledJobs();
    }

}

Web server configuration

public class TaskEngineWebServer {

    private static final Logger logger = Logger.getLogger(TaskEngineWebServer.class.getName());

    private Server server;

    public TaskEngineWebServer() {
        this(8585);
    }

    public TaskEngineWebServer(Integer port) {
        server = new Server(port);

        logger.info("Configuring rest service to start at url /r");
        ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
        //handler.getInitParams().put("com.sun.jersey.api.json.POJOMappingFeature", "true");
        PackagesResourceConfig packagesResourceConfig = new PackagesResourceConfig("com.hp.vf.scheduler.server.rest");

        ServletContainer servletContainer = new ServletContainer(packagesResourceConfig);
        handler.addServlet(new ServletHolder(servletContainer), "/r/*");

        server.setHandler(handler);
        logger.info("Done configuring rest service");
    }

    public void start() throws Exception {
        server.start();
    }

    public void stop() throws Exception {
        server.stop();
    }

    public boolean isStarted() {
        return server.isStarted();
    }

    public boolean isStopped() {
        return server.isStopped();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:13:05+00:00Added an answer on June 15, 2026 at 1:13 pm

    I finally figured out a clean solution, it involves creating my own MediaBodyWriter class and adding it as a provider. You have to make sure you are not using the jersey-bundle jar as the default jaxb to json provider will override yours.

    jars required

    jersey-core
    jersey-servlet
    jersey-server

    jackson-annotations
    jackson-databind
    jackson-core

    I found this MediaWriter example on the web somewhere. Sorry for not having the url but thanks to whoever write it.

    @Provider
    @Produces({ MediaType.APPLICATION_JSON })
    public class JacksonWriter implements MessageBodyWriter<Object> {
        private static final ObjectMapper MAPPER = new ObjectMapper();
    
        @Override
        public boolean isWriteable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
            return true;
        }
    
        @Override
        public long getSize(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return -1;
        }
    
        @Override
        public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
                OutputStream entityStream) {
            try {
                MAPPER.writeValue(entityStream, value);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        }
    }
    

    When it loads you will see a log message that your provider was loaded.

    This gave me the json output I was expecting as it does not rely on the JAXB annotations and simply uses the object mapper/ reflection. Probably less efficient but for my case it does not matter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a REST service in zend framework. I'm using zend server.
I'm trying to create a very simple REST server. I just have a test
Given: I'm trying to create a REST API using ASP.NET MVC . I'm using
I am trying to create a REST API for my app. The map.connect_resource :book
Situation I'm trying to create a REST API, where users can request responses in
I am trying to create a REST api using Spring MVC. Instead of writing
I'm trying to create a WCF client that accesses a REST API. The API
I'm trying to create a JSON REST api using Happstack. It should allow POSTS
So trying to create a rest service but I keep getting an error: If
I've got a simple REST based service for which I am trying to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.