【发布时间】:2012-06-14 18:41:57
【问题描述】:
关于这个话题有很多讨论,但没有真正的解决方案。
如果我使用这是我的问题
1) @Produce("application/Json") json 响应显示在
2) 如果我使用@Produce("application/html") 或@Produce("text/html"),那么很容易崩溃并出现 JAXB 异常错误:
未捕获的 Ext.Error:您正在尝试解码无效的 JSON 字符串:
HTTP 状态 500 - 找不到媒体类型的 JAXBContextFinder:text/html
类型状态报告
消息找不到媒体类型的 JAXBContextFinder:text/html
描述服务器遇到了一个内部错误(找不到媒体类型的 JAXBContextFinder:text/html),导致它无法完成此请求。
JBoss Web/3.0.0-CR2
我迫切希望得到一些帮助,并在表格中提出了一些解决方案: 1) 将内容类型更改为 text/html 2)更新ExtJs源代码 3) 解析 <预>从 JSON 响应中标记 不想做第二和第三,但在 Ist,我想要一个有效的 JSON 输出。我该怎么做?
这是我的服务类:
@POST @Path("/bulkUpdate") @Consumes("multipart/form-data") @Produces({"application/json"}) public ExtjsJson<DataException> uploadFile(MultipartFormDataInput input) { Map<String, List<InputPart>> uploadForm = input.getFormDataMap(); List<InputPart> inputParts = uploadForm.get("uploadedFile"); List<DataException> list = new ArrayList<DataException>(); final ExtjsJson<DataException> returnObj = new ExtjsJson<DataException>(); for (InputPart inputPart : inputParts) { try { MultivaluedMap<String, String> header = inputPart.getHeaders(); String fileName = getFileName(header); InputStream inputStream = inputPart.getBody(InputStream.class, null); byte[] bytes = IOUtils.toByteArray(inputStream); //handle the excel file upload and return the error if the file does not have valid data some like... DataException error = new DataException("supervisor", "columnName", 1, "SheetName", "this is not a valid supervisor"); list.add(error); } catch (IOException e) { e.printStackTrace(); } } returnObj.setSuccess(true); returnObj.setResults(list); return returnObj; }这是我的响应 Object DataException.java
@Data @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class DataException { //private static final long serialVersionUID = 1L; /** excel sheet name */ private String sheetName; /** row number of the excel sheet */ private int rowNumber; /** field name/cell header **/ private String fieldName; /** cell value */ private String fieldValue; private String description; }这是错误(带有标签的 JSON 响应)
未捕获的 Ext.Error:您正在尝试解码无效的 JSON 字符串:<pre style="word-wrap: break-word; white-space: pre-wrap;">{"total":1, "success":true,"results":[{"description":"这不是一个有效的主管","fieldName":"supervisor","fieldValue":"testPM","rowNumber":1,"sheetName" :"sheet1"}]}</pre>
【问题讨论】:
-
来吧伙计们,给我指路!!