users@jersey.java.net

JPA -> JAXB question

From: Felipe Gaúcho <fgaucho_at_gmail.com>
Date: Sat, 2 May 2009 13:57:23 +0200

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