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 4087770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:53:48+00:00 2026-05-20T18:53:48+00:00

I have a Books class with ArrayList of BookMeta objects , the name of

  • 0

I have a Books class with ArrayList of BookMeta objects , the name of the arraylist is bookList.

If the bookList holds more than one BookMeta, it works good for the clients as they receive an array. But if there is only one BookMeta object in bookList, they dont receive an array, instead they get one element. I took the following workaround for forcing the output to be one array :

@Provider
  public class JaxbContextResolver implements ContextResolver<JAXBContext> {

      private JAXBContext context;
      private Class[] types = {BookMeta.class, Books.class};

      public JaxbContextResolver() throws Exception {
          this.context = new JSONJAXBContext( JSONConfiguration.mapped().arrays("bookList").build(), types);
      }

      public JAXBContext getContext(Class<?> objectType) {
          for (Class type : types) {
             if (type == objectType) {
                  return context;
              }
          }
          return null;
      }
  }

Still I am not getting arrays. What else should I do ? Do I need to explicitly register the Provider classes ? I read somewhere they are automatically detected.

Thanks.

Edit : I am using Tomcat 6, and my web.xml looks like :

<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping> 
  • 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-05-20T18:53:49+00:00Added an answer on May 20, 2026 at 6:53 pm

    Got it working…had done a stupid mistake – the provider classes have to be kept in the resources folder (with property com.sun.jersey.config.property.packages) configured in web.xml

    Thanks for the help !

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

Sidebar

Related Questions

good morning, I have several objects that inherit from my father's class books and
To make it easy, lets say I have an arraylist allBooks containing class books
I have the following C# classes : public class Books { public List<Book> BookList;
Suppose I have my models set up already. class books(models.Model): title = models.CharField... ISBN
Consider this example (typical in OOP books): I have an Animal class, where each
Each book can have many authors. And each author can author many books. class
I have a class called Book; class Book { public string Name { get;
I have one grails application.In that I have one model class named Book. From
I have a class that has an list<Book> in it, and those Book objects
I have a set of Books objects, classs Book is defined as following :

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.