MediaType.TEXT_CSV for Jersey

╄→гoц情女王★ 提交于 2020-06-13 18:01:27

问题


Would it be possible to accept csv types? service.path(appPath).accept(mediaType).get(String.class)

There's no MediaType.TEXT_CSV defined in javax.ws.rs.core.MediaType. Have I missed something?

I am currently on Jersey 1.1.6.

Many thanks.


回答1:


You could define your own media type:

public final static String TEXT_CSV = "text/csv";
public final static MediaType TEXT_CSV_TYPE = new MediaType("text", "csv");



回答2:


csv is nothing but comma seperated text file

you can always use text\plain as media type to deal with CSV files - and deal with the CSV using frameworks such as Open CSV.

Or (in case of fileupload)

@Consumes(MediaType.MULTIPART_FORM_DATA)
public String process(@FormDataParam("file") InputStream csv) throws IOException {
//Process CSV file
}


来源:https://stackoverflow.com/questions/14520950/mediatype-text-csv-for-jersey

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!