SyndFeed syndFeed = new SyndFeed();
syndFeed.getEntries().add(entry1);
syndFeed.getEntries().add(entry2);
// make providers to return CsvSerializerProvider
CsvSyndFeedSerializerProvider syndFeedSerializerProvider =
new CsvSyndFeedSerializerProvider();
Field field = CsvSyndFeedSerializerProvider.class.getDeclaredField("providers");
field.setAccessible(true);
field.set(syndFeedSerializerProvider, new Providers() {
public <T> ContextResolver<T> getContextResolver(Class<T> contextType,
MediaType mediaType) {
return null;
}
public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
return null;
}
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType) {
return null;
}
@SuppressWarnings("unchecked")
public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType) {
return (MessageBodyWriter<T>)new CsvSerializerProvider();
}
});
ByteArrayOutputStream os = new ByteArrayOutputStream();
MultivaluedMapImpl<String, Object> httpHeaders = new MultivaluedMapImpl<String, Object>();
syndFeedSerializerProvider.writeTo(syndFeed,
syndFeed.getClass(),
null,
null,
MediaTypeUtils.CSV,
httpHeaders,