简体   繁体   中英

Using Resteasy with javassist?

I'm trying to use resteasy to serve out some entities fetched by spring-hibernate.

I've configured one method which returns a POJO and works as expected:

@GET
@Path("/test")
@Produces(MediaType.APPLICATION_XML)
public Episode getTestEpisode() {
  Episode e = new Episode();
  e.setEpisodename("test");
  return e;
}

Produces:

<episode episodeId="0">
 <combinedEpisodenumber>0.0</combinedEpisodenumber>
 <combinedSeason>0</combinedSeason>
 <episodename>test</episodename>
 <episodenumber>0</episodenumber>
 <seasonId>0</seasonId>
 <seasonnumber>0</seasonnumber>
</episode>

However, if I try and return something from spring/hibernate I get an error:

Could not find MessageBodyWriter for response object of type: com.company.domain.Episode_$$_javassist_27 of media type: application/xml

I imagine this is some magic with javassist, however I think it's confusing JAX-B by not being the expected class. Can I tell JAX-B where to look for the annotations, or can I get a POJO from this object?

Never used javassist directly, so not sure how it works.

You have to de-proxy the object.. found a utility method that works..

Converting Hibernate proxy to real object

public static <T> T initializeAndUnproxy(T entity) {
if (entity == null) {
    throw new 
       NullPointerException("Entity passed for initialization is null");
}

Hibernate.initialize(entity);
if (entity instanceof HibernateProxy) {
    entity = (T) ((HibernateProxy) entity).getHibernateLazyInitializer()
            .getImplementation();
}
return entity;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM