Wednesday, June 04, 2014

Wildfly and Resteasy are missing support for FastInfoset collection and map...

so, if you have a REST resource returning a java.util.List or a java.util.Map, like:
@Path("people")
@Produces({"application/fastinfoset"})
@Consumes({"*/*"})
public class SomeResource {
  
  @GET
  public List<SomeType> getAll() {
  ...
    
  // and / or

  @GET
  @Path("/map")
  public Map<String, SomeType> getMap() {
  ...
and you try to access it (e.g. curl -H "Accept: application/fastinfoset" http://localhost:8080/.../resources/map) you will see

Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/fastinfoset

or

Could not find MessageBodyWriter for response object of type: java.util.LinkedHashMap of media type: application/fastinfoset Unfortunately Resteasy "forgot" to implement two following classes:

@Provider
@Consumes("application/*+fastinfoset")
@Produces("application/*+fastinfoset")
public class FastInfosetCollectionProvider extends org.jboss.resteasy.plugins.providers.jaxb.CollectionProvider {
  @Override
  protected boolean suppressExpandEntityExpansion() {
    return false;
  }
}
@Provider
@Consumes("application/*+fastinfoset")
@Produces("application/*+fastinfoset")
public class FastInfosetMapProvider extends org.jboss.resteasy.plugins.providers.jaxb.MapProvider {
  @Override
  protected boolean suppressExpandEntityExpansion() {
    return false;
  }
}
I already sent my pull request, but in case it is never merged, you just have to provide two classes I showed above to make it work.