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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:42:46+00:00 2026-05-23T02:42:46+00:00

I have successfully set up a quick test of creating a REST-like service that

  • 0

I have successfully set up a quick test of creating a “REST-like” service that returns an object serialized to JSON, and that was quite easy and quick (based on this article).

But while returning JSON-ified objects was easy as peach, I have yet to see any examples dealing with input parameters that are not primitives. How can I pass in a complex object as an argument? I am using Apache CXF, but examples using other frameworks like Jackson are welcome too 🙂

Client side would probably be something like building a javascript object, pass it into JSON.stringify(complexObj), and pass that string as one of the parameters.

The service would probably look something like this

@Service("myService")
class RestService {
    @GET
    @Produces("application/json")
    @Path("/fooBar")
    public Result fooBar(@QueryParam("foo") double foo, @QueryParam("bar") double bar,
        @QueryParam("object") MyComplex object) throws WebServiceException {
    ...
    }
}

Sending serialized objects as parameters would probably quickly touch the 2KB URL-limit imposed by Internet Explorer. Would you recommend using POST in these cases, and would I need to change much in the function definitions?

  • 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-23T02:42:47+00:00Added an answer on May 23, 2026 at 2:42 am

    After digging a bit I quickly found out there are basically two options:

    Option 1

    You pass a “wrapper object” containing all the other parameters to the service. You might need to annotate this wrapper class with JAXB annotations like @XmlRootElement in order for this to work with the Jettison based provider, but if you use Jackson in stead there is no need. Just set the content type to the right type and the right message body reader will be invoked.
    This will only work for POST type services of course (AFAIK).

    Example

    This is just an example of turning the service mentioned in the original question into one using a wrapper object.

    @Service("myService")
    class RestService {
    
        @POST
        @Produces("application/json")
        @Path("/fooBar")
        public Result fooBar(
    
              /** 
              * Using "" will inject all form params directly into a ParamsWrapper 
              * @see http://cxf.apache.org/docs/jax-rs-basics.html
              */
              @FormParam("") FooBarParamsWrapper wrapper
    
            ) throws WebServiceException {
                doSomething(wrapper.foo);
        }
    }
    
    class ParamsWrapper {
      double foo, bar;
      MyComplexObject object;
    }
    

    Option 2

    You can provide some special string format that you pack your objects into and then implement either a constructor taking a string, a static valueOf(String s) or a static fromString(String s) in the class that will take this string and create an object from it. Or quite similar, create a ParameterHandler that does exactly the same.

    AFAIK, only the second version will allow you to call your services from a browser using JSONP (since JSONP is a trick restricted to GET). I chose this route to be able to pass arrays of complex objects in the URI.

    As an example of how this works, take the following domain class and service

    Example

    @GET
    @Path("myService")
    public void myService(@QueryParam("a") MyClass [] myVals) {
        //do something
    }
    
    class MyClass {
        public int foo;
        public int bar;
    
       /** Deserializes an Object of class MyClass from its JSON representation */
       public static MyClass fromString(String jsonRepresentation) {
               ObjectMapper mapper = new ObjectMapper(); //Jackson's JSON marshaller
               MyClass o= null;
               try {
                       o = mapper.readValue(jsonRepresentation, MyClass.class );
               } catch (IOException e) {
                        throw new WebApplicationException()
               }
               return o;
       }
    }
    

    A URI http://my-server.com/myService?a={"foo":1, "bar":2}&a={"foo":100, "bar":200} would in this case be deserialized into an array composed of two MyClass objects.

    2019 comment:
    Seeing that this answer still gets some hits in 2019, I feel I should comment. In hindsight, I would not recomment option 2, as going through these steps just to be able to be able to do GET calls adds complexity that’s probably not worth it. If your service takes such complex input, you will probably not be able to utilize client side caching anyway, due to the number of permutations of your input. I’d just go for configuring proper Cross-Origin-Sharing (CORS) headers on the server and POST the input. Then focus on caching whatever you can on the server.

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

Sidebar

Related Questions

I have successfully trained a classifier (bayesnet) and constructed a test set (ARFF-format), which
I have have successfully set up a list that pulls users from a database
I have set an event successfully using myEntry.setTitle(new PlainTextConstruct(TEST)) myEntry.setContent(new PlainTextConstruct(See how much text
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed
I have successfully set up an HgWebDir instance over CGI with Apache, and I
I'm using the the new UIAppearance API and have successfully set the tint color
I have not found any way to successfully set a screen resolution on my
I have scrip contain command line: set dir=%1 cd %dir% test.bat echo successful When
I have successfully created a feature in sharepoint that modifies the existing edit dialog
I have successfully set up my twitter callback on my webpage and everything is

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.