2017-06-15 55 views
0

我正在嘗試使用Rest Assured將Spring Rest文檔與Grails 3.2.9應用程序集成。在集成測試期間,它正在產生有效負載處理例外。Grails 3.2.9:Spring Rest文檔使用Rest確保給出有效負載處理例外:com.fasterxml.jackson.core.JSONParseException

完整堆棧跟蹤:

org.springframework.restdocs.payload.PayloadHandlingException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 
at [Source: [[email protected]; line: 1, column: 2] 
    at org.springframework.restdocs.payload.JsonContentHandler.readContent(JsonContentHandler.java:84) 
    at org.springframework.restdocs.payload.JsonContentHandler.findMissingFields(JsonContentHandler.java:50) 
    at org.springframework.restdocs.payload.AbstractFieldsSnippet.validateFieldDocumentation(AbstractFieldsSnippet.java:113) 
    at org.springframework.restdocs.payload.AbstractFieldsSnippet.createModel(AbstractFieldsSnippet.java:74) 
    at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:64) 
    at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:192) 
    at org.springframework.restdocs.restassured.RestDocumentationFilter.filter(RestDocumentationFilter.java:63) 
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73) 
    at org.springframework.restdocs.restassured.RestAssuredRestDocumentationConfigurer.filter(RestAssuredRestDocumentationConfigurer.java:65) 
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73) 
    at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1574) 
    at com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:159) 
    at so.con.BaseRestDocTestSetup.$tt__createDoc(BaseRestDocTestSetup.groovy:130) 
    at so.con.BaseRestDocTestSetup.createDoc_closure4(BaseRestDocTestSetup.groovy) 
    at groovy.lang.Closure.call(Closure.java:414) 
    at groovy.lang.Closure.call(Closure.java:430) 
    at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70) 
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) 
    at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67) 
    at so.con.v1.docs.ConfApiDocSpec.test and document get request for /conf getting conf-list as Response(ConfApiDocSpec.groovy:63) 
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') 
at [Source: [[email protected]; line: 1, column: 2] 
    at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) 
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) 
    at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2689) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:878) 
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:772) 
    at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3834) 
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3783) 
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2929) 
    at org.springframework.restdocs.payload.JsonContentHandler.readContent(JsonContentHandler.java:81) 
    ... 19 more 

請幫我解決這個問題。

+0

從錯誤消息看來,您期待JSON,但正在生成XML。 –

+0

我如何確定正在檢索什麼類型的數據? –

回答

0

您試圖使用JSON解碼器解析XML。爲您的請求使用Accept-Encoding標題,並在那裏提供預期的格式。

相關問題