users@jersey.java.net

Re: [Jersey] 2 different xml representation for the same data

From: Marc Hadley <marc.hadley_at_oracle.com>
Date: Thu, 1 Apr 2010 10:45:57 -0400

What you have so far looks fine to me - no media-type abuse detected.

You might consider adding links to the representations (e.g. each order could include a link to resource for that order) so clients don't have to construct them.

Marc.

On Apr 1, 2010, at 8:55 AM, Florian Hehlen wrote:

> I have this interesting use case….
>
>
> I would like to be able to retrieve a list of objects or alternatively just a list of id’s. I am thinking that this is just a different representation of the same data so I would like to use the same url with different media types.
>
> So it looks a like this…
>
> Request 1:
> curl http://store/orders/query?state=back-ordered
>
> reply 1:
> <orders>
> <order>
> <id>1</id>
> <state>back-ordered</state>
> /* plus all other properties */
> </order>
> <order>
> <id>2</id>
> <state>back-ordered</state>
> /* plus all other properties */
> </order>
> </orders>
>
> Request 2:
> curl -s -H Accept:application/ids http://store/orders/query?state=back-ordered
>
> reply 2:
> <pairs>
> <pair key=”1” value=”order” />
> <pair key=”2” value=”order” />
> </pairs>
>
>
> Has anyone else been down this path? It feels quite elegant to want to do it this way. I have written my own MessageBodyWriter and it works fine. But since both representations are xml I was hoping to be able to re-use existing jersey providers so I do not have to write my own serialization/deserialization code.
>
> At the end of the day I just want to re-direct the calls to different methods in my resource
>
> @Path(“orders/query”)
> Public class Resource {
>
> @GET
> @Produces({“application/xml”})
> Public Order[] findByState(@QueryParam(“state”)String state) {
> //…
> }
>
> @GET
> @Produces({“application/ids”})
> Public Pair[] findByStateAsId(@QueryParam(“state”)String state) {
> //…
> }
> }
>
> Am I barking up the wrong tree? Am I abusing media-types?
>
> Cheers,
> Flo.
>
> The information in this e-mail is intended only for the person or entity to which it is addressed.
>
> It may contain confidential and /or privileged material. If someone other than the intended recipient should receive this e-mail, he / she shall not be entitled to read, disseminate, disclose or duplicate it.
>
> If you receive this e-mail unintentionally, please inform us immediately by "reply" and then delete it from your system. Although this information has been compiled with great care, neither IMC Financial Markets & Asset Management nor any of its related entities shall accept any responsibility for any errors, omissions or other inaccuracies in this information or for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail or its attachments. In the event of incomplete or incorrect transmission, please return the e-mail to the sender and permanently delete this message and any attachments.
>
> Messages and attachments are scanned for all known viruses. Always scan attachments before opening them.