@Provider@Produces("text/csv")publicclassCSVMessageBodyWriterimplementsMessageBodyWriter<JaxbList>publicstaticfinalStringCONTENT_DISPOSITION_HEADER="Content-Disposition";privatefinalstaticHeaderDelegate<ContentDispositionHeader>header=RuntimeDelegate.getInstance().createHeaderDelegate(ContentDispositionHeader.class);publiclonggetSize(JaxbListt,Class<?>type,TypegenericType,Annotation[]annotations,MediaTypemediaType){return-1;}publicbooleanisWriteable(Class<?>type,TypegenericType,Annotation[]annotations,MediaTypemediaType){returnCsvSerializer.class.isAssignableFrom(type);}publicvoidwriteTo(JaxbListt,Class<?>type,TypegenericType,Annotation[]annotations,MediaTypemediaType,MultivaluedMap<String,Object>httpHeaders,OutputStreamentityStream)throwsIOException,WebApplicationException{// set content disposition. This will enable browsers to open excel ContentDispositionHeadercontentDispositionHeader=ContentDispositionHeader.createContentDispositionHeader(MediaTypeUtils.CSV_TYPE);contentDispositionHeader.setFileName("representation");//$NON-NLS-1$ httpHeaders.putSingle(CONTENT_DISPOSITION_HEADER, header.toString(contentDispositionHeader)); Charsetcharset=Charset.forName(ProviderUtils.getCharset(mediaType));OutputStreamWriterwriter=newOutputStreamWriter(entityStream,charset);PrintWriterprintWriter=newPrintWriter(writer);Iterator<String[]>rows=((CsvSerializer)t).getEntities();while(rows.hasNext()){printWriter.println(CsvWriter.getCSVRow(rows.next()));}printWriter.flush();}}
My REST Application
@Path("app/v3")
@GZIP
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, "text/csv"})
public class ApplicationREST
When I run in debug mode I can hit my JaxRsActivator class, so I know that the providers are being loaded. However I get the error "Could not find MessageBodyWriter for response object of type: net.comp.jaxb.JaxbList of media type: text/csv"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My MessageBodyWriter
My REST Application
Extension of Application
When I run in debug mode I can hit my JaxRsActivator class, so I know that the providers are being loaded. However I get the error "Could not find MessageBodyWriter for response object of type: net.comp.jaxb.JaxbList of media type: text/csv"