users@jersey.java.net

Re: [Jersey] JPA -> JAXB question

From: Felipe Gaúcho <fgaucho_at_gmail.com>
Date: Mon, 4 May 2009 11:20:00 +0200

much better, less tricky code in the service :) thanks.......

On Mon, May 4, 2009 at 10:57 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi,
>
> The instance returned by the resource method is the instance that is
> marshaled by JAXB, essentially using the following:
>
> http://java.sun.com/javase/6/docs/api/javax/xml/bind/Marshaller.html#marshal(java.lang.Object,%20java.io.OutputStream)
>
> So you could do:
>
>        @GET
>        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
>        @Path("/read/{id}")
>        public Object read(@PathParam("id") String id) {
>                return userFacade.read(new Long(id));
>        }
>
> and the same behavior will occur.
>
> Paul.
>
> On May 2, 2009, at 1:57 PM, Felipe Gaúcho wrote:
>
>> I have this method that reads from the database and expose the
>> serialized entity on the RESTful interface of Jersey...
>>
>> everything works fine.. but I got a curious behavior.
>>
>> check out this method:
>>
>>        @GET
>>        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON
>> })
>>        @Path("/read/{id}")
>>        public FpUser read(@PathParam("id") String id) {
>>                return userFacade.read(new Long(id));
>>        }
>>
>>
>> this works fine.. BUT: I have this hierarchy:
>>
>> class FpUser
>> class FpUserWritable extends FpUser
>>
>> when I run the above method, the returned XML represents a subclass
>> FpUserWritable... not what I want..
>>
>> and then, I tried this method rewriting:
>>
>>        @GET
>>        @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON
>> })
>>        @Path("/read/{id}")
>>        public JAXBElement<FpUser> read(@PathParam("id") String id) {
>>                return new JAXBElement<FpUser>(FpUser.QUALIFIED_NAME,
>> FpUser.class,
>>                                        userFacade.read(new Long(id)));
>>        }
>>
>>
>> done, the returned type now is the superclass FpUser instead of its
>> subclass...
>>
>>
>> I am just trying to understand why the first code returned the full
>> JPA entity -....
>>
>> other curiosity: if I return a Collection<FpUser> it works natively,
>> without any adaptation needed.... :(
>>
>>
>> --
>>
>> Please help to test this application:
>> http://fgaucho.dyndns.org:8080/cejug-classifieds-richfaces
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
Please help to test this application:
http://fgaucho.dyndns.org:8080/cejug-classifieds-richfaces