The moose likes Distributed Java and the fly likes passing response as json vs. string array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "passing response as json vs. string array " Watch "passing response as json vs. string array " New topic

passing response as json vs. string array

Shashank Sharma
Ranch Hand

Joined: Sep 27, 2006
Posts: 91
Hello all.
I am working on a client server architecture application. for which I am using Restlets Clients Response and Http Connector For Remote procedure Call.
I want to pass two objects as response.
so I am creating json for both using Jakson object mapper.

now In order to pass it to the client I can
a)pass the above two json string as a string separated with a delimiter like'~'
b)pass a string array having two of these json strings.
c)create a json having two of these json strings its content //not able to implement.
d)send a restlet object

I really dont wana use a) there can be chances that my string contains the delimiter as the content value.
b)am facing a parsing error....
c)it is working fine for me... need to figure if there is any chance of data loss.
d)heavy response... want to avoid....and want to reduce no of client -server calls.

would like to know you comment on the above mentioned procedures for sending response.

Thanks for your time reading this post.
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

I think the answer depends on the response content-type you want to have. If you are specifying application/json they you have to return a json string, so option c) is the correct choice. I am not sure what kind of data loss are you talking about in this case.

apigee, a better way to API!
Shashank Sharma
Ranch Hand

Joined: Sep 27, 2006
Posts: 91
Hello Nitesh,

So far option c i.e creating a JSON of a String arrays having JSON as content works for me. For 'data loss' i mean chance of my json breaking up due to the type of content. as there will be a lott of data being passed as json string.

I agree. Here's the link: http://aspose.com/file-tools
subject: passing response as json vs. string array
Similar Threads
How to print java Map name/value pair through JSON object in JS
[jersey/jax-rs] json object value string has extra quotes, jsonp, service chaining‏
Javascript array to JSON object via jquery
Reading a 'Collection' object from JSON
JSON, dynamically formatting, etc.