Could not serialize object cause of HibernateProxy

You can do without manually unproxying everything by using a custom TypeAdapter. Something along these lines: /** * This TypeAdapter unproxies Hibernate proxied objects, and serializes them * through the registered (or default) TypeAdapter of the base class. */ public class HibernateProxyTypeAdapter extends TypeAdapter<HibernateProxy> { public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() { @Override … Read more

Staying DRY with JAX-RS

Here is a workaround I’m using: Define a constructor for the BaseService with ‘id’ and ‘xyz’ as params: // BaseService.java public abstract class BaseService { // JAX-RS injected fields protected final String id; protected final String xyz; public BaseService (String id, String xyz) { this.id = id; this.xyz = xyz; } } Repeat the constructor … Read more

Practical advice on using Jersey and Guice for RESTful service

Guice integration with Jersey has not stagnated. The opposite is true. Thanks to Paul and his cohorts behind Jersey, the latest 1.7 release contains a special JerseyServletModule class to work with Guice-based servlets. Guice-based constructor injection into JAX-RS resource works! The issue is using JAX-RS annotations such as @QueryParam in the constructor of a JAX-RS … Read more

Get ServletContext in JAX-RS resource

Furthermore, @Resource annotation might not work. Try this @javax.ws.rs.core.Context ServletContext context; The injection doesn’t happen until you hit the service method public class MyService { @Context ServletContext context; public MyService() { print(“Constructor ” + context); // null here } @GET @Path(“/thing”) { print(“in wizard service ” + context); // available here

javax.xml.bind.JAXBException: Class *** nor any of its super class is known to this context

JAX-RS implementations automatically support marshalling/unmarshalling of classes based on discoverable JAXB annotations, but because your payload is declared as Object, I think the created JAXBContext misses the Department class and when it’s time to marshall it it doesn’t know how. A quick and dirty fix would be to add a XmlSeeAlso annotation to your response … Read more

Inject an EJB into JAX-RS (RESTful service)

I am not sure this is supposed to work. So either: Option 1: Use the injection provider SPI Implement a provider that will do the lookup and inject the EJB. See: @EJB injection. Example for com.sun.jersey:jersey-server:1.17 : import com.sun.jersey.core.spi.component.ComponentContext; import com.sun.jersey.core.spi.component.ComponentScope; import com.sun.jersey.spi.inject.Injectable; import com.sun.jersey.spi.inject.InjectableProvider; import javax.ejb.EJB; import javax.naming.Context; import javax.naming.InitialContext; import javax.ws.rs.ext.Provider; import java.lang.reflect.Type; … Read more

How to choose between Jersey, Apache Wink and JBoss RESTEasy? [closed]

JAX-RS Implementations Jersey Reference Implementation Usually the most cutting edge Supports true asynchronous (ie web sockets etc…) connections through either Atmosphere or 2.0 version. Has support for Spring and standard injection containers (ie @Inject). Glassfish bundles it. Its much more modular than the other JAX-RS projects. It has a kick ass URI Builder Does not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)