2016-09-30 104 views
0

我有問題與JHipster發佈休息泉服務。 該服務包含一個MultipartFile,參數和一個JSON對象。據我所知,我應該能夠發佈如下:JHipster,MultiPart和JSON的春季休息服務,招搖/捲曲錯誤

public @ResponseBody 
    ResponseEntity<DocumentId> addDoc(@RequestPart(required = true) MultipartFile file, @RequestPart(required = false) String folder, @RequestPart(required = true) MetadataDoc metadata) 

招搖API無法識別參數「元數據」,宣佈其爲「不確定」的數據類型。當我嘗試做一個捲曲的要求,我得到以下錯誤:

2016-09-30 13:27:15.174 WARN 30451 --- [ XNIO-2 task-12] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported 
2016-09-30 13:27:15.298 DEBUG 30451 --- [ XNIO-2 task-14] c.q.smartgov.aop.logging.LoggingAspect : Enter: com.queres.smartgov.web.rest.errors.ExceptionTranslator.processRuntimeException() with argument[s] = [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported] 
2016-09-30 13:27:15.298 DEBUG 30451 --- [ XNIO-2 task-14] c.q.smartgov.aop.logging.LoggingAspect : Exit: com.queres.smartgov.web.rest.errors.ExceptionTranslator.processRuntimeException() with result = <500 Internal Server Error,[email protected],{}> 

的捲曲請求:

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTQ3Njk3NjY3N30.82FRMRSrrniEQcIhI6DtHEFf5ln3OSjS_6OWy-1d8h3Cp5MjRuxo04IuIxAX_WC8YJJ1QyLrq7loLUSQ8RV_Gw' -F [email protected]"result.txt" -F folder=folde -F metadata={"clave":"2","valor":"1"} 'http://127.0.0.1:8080/sd_api/api/almacen/addDoc' 

我已經嘗試了很多東西,什麼建議嗎?

在此先感謝!

回答

0

最後我把解釋的JSON參數聲明爲一個字符串,我自己解析它。

如果有人知道如何將參數發佈爲JSON對象,我將不勝感激。

ObjectMapper mapper = new ObjectMapper(); 
     try { 
      return mapper.readValue(stringValue, mapper.getTypeFactory().constructCollectionType(List.class, MetadataDoc.class)); 
     } catch (IOException ex) { 
      //throw exception 
     }