Reg:Supporting new Representation

15 views
Skip to first unread message

karthik bashyam

unread,
Jan 17, 2012, 4:40:02 AM1/17/12
to restinpractice
Suppose for example restbucks service should support multiple
mediaTypes.The code in the book only supports xml using a seperate
representation class, and using JAX-B we are marshalling and sending
the response.If Users of the service are expecting the service to
return the data based on their request say json or some other format.
Which one of the below designs is best
Create a new representation class and in the toString method handle
json representation logic
or

Write a condition in the existing representation class to send json
response

Jim Webber

unread,
Jan 20, 2012, 4:51:25 AM1/20/12
to restinp...@googlegroups.com
Hi Karthik,

If you're asking should you write code like this:

if(isXML()) {
...
} else if (isJSON()) {
..
}

then I'd say I'm against it. Off the top of my head, I think I like a channel abstraction.

That is, you build an input and output channels containing the appropriate de/serialisers to match your Content-Type and Accept headers. The business logic at the top of the channels should deal in an abstract form like a request/response hash map or tree.

Does that make sense?

Jim

Reply all
Reply to author
Forward
0 new messages