0

I want to upload a list of objects to my webserver through a REST API. I'm not sure if it's possible to do it with a REST call?

The object looks like this:

class Position {
    private Date date;
    private Double latitude;
    private Double longitude;
}

Can I do it with something like this:

http://www.example.com/positions?userId=abc&position1=position1&position2=position2 ?

Or should I create a JSON representation of it and upload/put that to the webserver?

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • Yes, this should be standard functionality with Jersey, this question may help you http://stackoverflow.com/questions/7823070/how-to-unmarshall-jax-rs-webservice-response-json-array-correctly – David Mar 12 '14 at 16:05
  • will you consider sending a payload with your HTTP request? If not you will have to find some hack in the url parameters. Amazon has something similar (see examples on http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CartAdd.html ) – XSen Mar 12 '14 at 16:07

2 Answers2

1

You should be able to do this using the Jersey REST framework. It might be enough just to enable the POJO mapping feature.

We do something similar in our project, where we marshal Java data types into JSON, and return that in our HTTP response.

ktm5124
  • 11,861
  • 21
  • 74
  • 119
  • Very doable - we use RestEasy but it's almost the same. Generally, we just JAXB annotated our POJOs and then your REST layer can work with the JSON. We created a helper method, `String toJSON(Ojbect obj)` that used the ObjectMapper to write the JSON value and that String gets put in the request body and you set content-type = 'application/json' and off you go. – mikemil Mar 12 '14 at 16:22
  • Thanks for your suggestion! Is it possible to use Google gson for this as well? – Peter Warbo Mar 12 '14 at 22:48
-1

Use http POST instead of GET. You don't have to use json.

gtsouk
  • 5,208
  • 1
  • 28
  • 35