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

  • Home
  • SEARCH
  • 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 6187403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:03:08+00:00 2026-05-24T02:03:08+00:00

i am trying to create a REST service that accepts a List of objects

  • 0

i am trying to create a REST service that accepts a List of objects from a client and gives back a zip file.
i understand how to give back the zip file alright.
But i am right now trying to figure out a way i can pass a List of objects from a REST client/browser to the Rest service and how do i accept the List in the REST service.

Should this be done via XML input ?
or maybe the @consumes annotation could help?

Much thanks .

Som

  • 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-24T02:03:09+00:00Added an answer on May 24, 2026 at 2:03 am

    You need to think out more clearly what you wish to do. There’s no really good reason for taking a list of objects and returning a ZIP of them; you might as well use a local zip program (which just about all computers already have). That indicates that we instead need to be looking at something sensible: for example, a list of names of objects that you’ll return a ZIP of, that makes a lot of sense. There are other sensible things you could be doing too, but you have to work it out in your mind what you want to happen.

    Because you mention “@consumes annotation”, I’m going to assume you’re using JAX-RS (i.e., Java). That’s nice, because it’s entirely possible to do on-the-fly ZIP generation with that; the content type you want to produce is application/zip. The easiest way I’ve found to handle the specification of the list of descriptions of things to return is as a wrapped list, where you use something like JAXB to do the mapping (which gives you XML support; some frameworks also support JSON off the same data models). To do a wrapped list, you use something like this:

    @XmlRootElement
    public class Wrapper {
        @XmlElement
        public List<String> item;
    }
    

    That then produces/handles XML documents like this (a three item list):

    <wrapper>
        <item>foo</item>
        <item>...</item>
        <item>bar</item>
    </wrapper>
    

    You’ll need to set up the @Consumes annotation so that the content type accepted is application/xml (at least), and also consider what type of operation is involved and on what resource.


    [EDIT]: In order to create a REST service that takes a list of strings as arguments, the easiest method is indeed to use a wrapper object, much as above. (You can’t take a raw list; it needs to be a well-formed XML document when it’s on the wire.) We then set up the annotated service method like this:

    @POST
    @Path("somewhere/{id}")
    @Consumes("application/xml")
    @Produces("application/zip")
    public Response getSomeBytesForList(@PathParam("id") String id, Wrapper req) {
        List<String> items = req.item; // For example...
        byte[] zip = generateZipBytes(id, items); // or however
        return Response.ok(zip).type("application/zip").build();
    }
    

    The key is that the req argument (the name is arbitrary, of course) is the only argument that is not annotated, that it is of a type that is JAXB-enabled, and there is an overall @Consumes ("application/xml") annotation to enable the JAXB processing of the request body. (I handle the returning of a ZIP by generating the Response directly rather than relying on the framework to do the processing for me; this lets me control the content type handling a little more precisely.)

    Also note that some frameworks can also transfer JAXB-annotated objects as JSON documents, just by having a bit of extra annotation; you just state that the method can accept both "application/xml" and "application/json" in the @Consumes annotation. I do not know whether this applies to the framework you are using (I’ve only tested it with Apache CXF).

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

Sidebar

Related Questions

I am trying to create a rest service that will return a list of
So I'm trying to create a C# WCF REST service that is called by
I am trying to create a WCF client that operates with an http rest
I'm trying to create a REST web service that exposes the following Django model:
I'm trying to create a REST service in zend framework. I'm using zend server.
I've got a simple REST based service for which I am trying to create
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
I have developed a sample WCF REST service that accepts that creates an Order
I'm trying to create a REST service defined as: @POST @Path(/path) @Consumes(MediaType.APPLICATION_XML) @Produces(multipart/mixed) public

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.